首页 \ 问答 \ 运行时错误'1004',已经研究并尝试了几个推荐的解决方案无济于事(Run Time Error '1004', have researched and tried several recommended solutions to no avail)

运行时错误'1004',已经研究并尝试了几个推荐的解决方案无济于事(Run Time Error '1004', have researched and tried several recommended solutions to no avail)

我试图用公式填充范围并继续得到运行时错误'1004'。 错误发生在我已加星标表格的行(“预测”)。范围(“H125”)。公式= formulaTest 。 我的Sub中的代码如下:

Sub FirmShareFill()

Dim RampUp As Range
Dim RampBas As Range
Dim RampDn As Range
Dim Numbering As Range
Dim Approval As Range
Dim PeakShare As Range



Dim tcount As Byte
Dim bcount As Byte
Dim ubdcount As Byte
Dim yearRange2 As Byte

year = Worksheets("Inputs").Range("B6").Value
cntry = Worksheets("Inputs").Range("B5").Value
bnd = Worksheets("Inputs").Range("B3").Value
typ = Worksheets("Inputs").Range("B2").Value
cat = Worksheets("Inputs").Range("B4").Value

tcount = bnd * cat + bnd
ubdcount = tcount * 2 + 1
yearCount = year * 4 - 1

        For ubd = 1 To 3
        For t = 1 To typ
        For b = 1 To bnd
        For c = 1 To cat
        For i = 1 To cntry

        Set RampUp = Columns(7).Find(What:="Ramp_Up" & i, MatchCase:=True).Offset(0, 1)
        Set RampBas = Columns(7).Find(What:="Ramp_Bas" & i, MatchCase:=True).Offset(0, 1)
        Set RampDn = Columns(7).Find(What:="Ramp_Dn" & i, MatchCase:=True).Offset(0, 1)

        Set Numbering = Sheets("Inputs").Range("B13")
        Set Approval = Columns(6).Find(What:="Approval", MatchCase:=True).Offset(i, 2 + ubd)


        bcount = c + (cat + 1) * (b - 1)

        If t = 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c)
        ElseIf t = 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount)
        ElseIf t > 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount)
        ElseIf t > 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount)

        ElseIf t = 1 And b = 1 And ubd = 2 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c + ubdcount)
        ElseIf t = 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount + ubdcount)
        ElseIf t > 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount + ubdcount)
        ElseIf t > 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount + ubdcount)

        ElseIf t = 1 And b = 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c + 2 * ubdcount)
        ElseIf t = 1 And b > 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount + 2 * ubdcount)
        ElseIf t > 1 And b = 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount + 2 * ubdcount)
        ElseIf t > 1 And b > 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount + 2 * ubdcount)
        End If

        Dim formulaTest As String

        formulaTest = "=IF(" & Numbering.Address(False, False) & "<" & Approval.Address & ","", " & PeakShare.Address & " * " & RampUp.Address & ")"

        If ubd = 1 Then
        **Sheets("Forecast").Range("H125").Formula = formulaTest**
        ActiveCell.Offset(1, 0).Select

        ElseIf ubd = 2 Then
        Range(ActiveCell, ActiveCell.Offset(0, yearRange2)).Formula = "=IF(" & Numbering.Address(False, False) & " < " & Approval.Offset(1, 0).Address & ","", " & PeakShare.Address & " * " & RampBas.Address & ""

        ElseIf ubd = 3 Then
        Range(ActiveCell, ActiveCell.Offset(0, yearRange2)).Formula = "=IF(" & Numbering.Address(False, False) & " < " & Approval.Offset(1, 0).Address & ","", " & PeakShare.Address & " * " & RampDn.Address & ""

        End If


        Next i

        ActiveCell.Offset(1, 0).Select

        Next c
        Next b
        Next t
        Next ubd



End Sub

我相信错误可能与我如何宣布范围“编号”范围有关,但到目前为止我一直无法弄明白。 我已多次在同一张纸上使用此代码,唯一的区别是我在另一张纸上设置了一个范围,编号。


I am trying to fill a range with a formula and continue to get a runtime error '1004'. The error occurs at the line I have starred Sheets("Forecast").Range("H125").Formula = formulaTest. The code in my Sub is as follows:

Sub FirmShareFill()

Dim RampUp As Range
Dim RampBas As Range
Dim RampDn As Range
Dim Numbering As Range
Dim Approval As Range
Dim PeakShare As Range



Dim tcount As Byte
Dim bcount As Byte
Dim ubdcount As Byte
Dim yearRange2 As Byte

year = Worksheets("Inputs").Range("B6").Value
cntry = Worksheets("Inputs").Range("B5").Value
bnd = Worksheets("Inputs").Range("B3").Value
typ = Worksheets("Inputs").Range("B2").Value
cat = Worksheets("Inputs").Range("B4").Value

tcount = bnd * cat + bnd
ubdcount = tcount * 2 + 1
yearCount = year * 4 - 1

        For ubd = 1 To 3
        For t = 1 To typ
        For b = 1 To bnd
        For c = 1 To cat
        For i = 1 To cntry

        Set RampUp = Columns(7).Find(What:="Ramp_Up" & i, MatchCase:=True).Offset(0, 1)
        Set RampBas = Columns(7).Find(What:="Ramp_Bas" & i, MatchCase:=True).Offset(0, 1)
        Set RampDn = Columns(7).Find(What:="Ramp_Dn" & i, MatchCase:=True).Offset(0, 1)

        Set Numbering = Sheets("Inputs").Range("B13")
        Set Approval = Columns(6).Find(What:="Approval", MatchCase:=True).Offset(i, 2 + ubd)


        bcount = c + (cat + 1) * (b - 1)

        If t = 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c)
        ElseIf t = 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount)
        ElseIf t > 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount)
        ElseIf t > 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount)

        ElseIf t = 1 And b = 1 And ubd = 2 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c + ubdcount)
        ElseIf t = 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount + ubdcount)
        ElseIf t > 1 And b = 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount + ubdcount)
        ElseIf t > 1 And b > 1 And ubd = 1 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount + ubdcount)

        ElseIf t = 1 And b = 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share", MatchCase:=True).Offset(4 + i, c + 2 * ubdcount)
        ElseIf t = 1 And b > 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, bcount + 2 * ubdcount)
        ElseIf t > 1 And b = 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, c + tcount + 2 * ubdcount)
        ElseIf t > 1 And b > 1 And ubd = 3 Then
            Set PeakShare = Columns(5).Find(What:="Peak Share" & c, MatchCase:=True).Offset(4 + i, tcount + bcount + 2 * ubdcount)
        End If

        Dim formulaTest As String

        formulaTest = "=IF(" & Numbering.Address(False, False) & "<" & Approval.Address & ","", " & PeakShare.Address & " * " & RampUp.Address & ")"

        If ubd = 1 Then
        **Sheets("Forecast").Range("H125").Formula = formulaTest**
        ActiveCell.Offset(1, 0).Select

        ElseIf ubd = 2 Then
        Range(ActiveCell, ActiveCell.Offset(0, yearRange2)).Formula = "=IF(" & Numbering.Address(False, False) & " < " & Approval.Offset(1, 0).Address & ","", " & PeakShare.Address & " * " & RampBas.Address & ""

        ElseIf ubd = 3 Then
        Range(ActiveCell, ActiveCell.Offset(0, yearRange2)).Formula = "=IF(" & Numbering.Address(False, False) & " < " & Approval.Offset(1, 0).Address & ","", " & PeakShare.Address & " * " & RampDn.Address & ""

        End If


        Next i

        ActiveCell.Offset(1, 0).Select

        Next c
        Next b
        Next t
        Next ubd



End Sub

I believe the error may have something to do with how I declared the range "numbering" range, but as of yet I have been unable to figure it out. I have used this code on the same sheet many times, the only difference being that I have set a range, numbering, on a different sheet.


原文:https://stackoverflow.com/questions/42536691
更新时间:2022-04-12 19:04

最满意答案

我不确定你是否在寻找

  1. 使用标题和HTML代码通过Wordpress编辑器进行快速修复
  2. 通过Wordpress html编辑器快速修复手动重新创建字幕代码
  3. 通过functions.php文件和wp-includes / media.php中的add_shortcode()进行永久性修复
  4. 通过CSS永久修复可能会影响所有标题。

我尽量保持你的代码不受影响

<div style="text-align:center;">
// This should align the entire block [it worked for me at least]
    <div style="display:inline-block;">
        <div style="float:left;">
        // Takes care of the centering down the middle
            [caption align="aligncenter" width="150" caption="Protein rest"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest.jpg">
<img title="Mash during protein rest" src="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest-150x144.jpg" alt="Mash during protein rest" width="150" height="144" />
</a>[/caption]
        //Your caption code above with alignnone changed to aligncenter
        </div>
        <div style="float:left;">
            [caption align="aligncenter" width="143" caption="Saccharification rest" captionalign="center"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest.jpg">
<img  title="Mash during saccharification rest" src="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest-143x150.jpg" alt="Mash during saccharification rest" width="143" height="150" />
</a>[/caption]
        </div>
    </div> // End the Block Div
</div> // End the Center Div

[编辑:刚刚看到你回答了自己 - .-无论如何发帖:D]


I am not sure whether you are looking for

  1. A Quick Fix via Wordpress Editor using the caption and html code
  2. A Quick Fix via Wordpress html Editor recreating the caption code by hand
  3. A Permanent fix via the functions.php file and the add_shortcode() in wp-includes/media.php
  4. A Permanent Fix via CSS which might affect all captions.

I am giving 1 keeping your code as untouched as possible

<div style="text-align:center;">
// This should align the entire block [it worked for me at least]
    <div style="display:inline-block;">
        <div style="float:left;">
        // Takes care of the centering down the middle
            [caption align="aligncenter" width="150" caption="Protein rest"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest.jpg">
<img title="Mash during protein rest" src="http://www.mysite.com/wp-content/uploads/2008/06/protein-rest-150x144.jpg" alt="Mash during protein rest" width="150" height="144" />
</a>[/caption]
        //Your caption code above with alignnone changed to aligncenter
        </div>
        <div style="float:left;">
            [caption align="aligncenter" width="143" caption="Saccharification rest" captionalign="center"]
<a href="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest.jpg">
<img  title="Mash during saccharification rest" src="http://www.mysite.com/wp-content/uploads/2008/06/saccharification-rest-143x150.jpg" alt="Mash during saccharification rest" width="143" height="150" />
</a>[/caption]
        </div>
    </div> // End the Block Div
</div> // End the Center Div

[EDIT : Just saw you answered yourself -.- posting anyway :D]

相关问答

更多
  • 这里有一些工作让你开始。 html, body { box-sizing: border-box; } h1 { text-align: center; } .wrapper { text-align: center; } p { text-align: left; margin-top: 20px; border: 1px solid #000; padding: 10px; height: 150px; } .fitness-section { display ...
  • 您可以将这些数字放入无边界的两列表格中。 你的照片实际上放在一个不可见的桌子上。 然后,您可以为每个图片添加标题,Word将提供不同的图形编号。 You can put the figures into a borderless two-column table. Your pictures are actually put in an invisible table. Then you can add captions to each of the pictures and Word will provi ...
  • 使用HTML5 figure元素包装每个图像,然后在每个图像中添加一个figcaption元素以figcaption标题。 您可以将图形的display属性设置为inline-block以使它们彼此相邻,然后将它们设置为类似于当前使用.pic类设置图像样式的样式。 Use the HTML5 figure element to wrap each image and then add a figcaption element within each to conation your captions. Yo ...
  • 给这个镜头: 在您各自网站的自定义样式中,将这些样式添加到表单的父包装中。 我已经用当前的代码和主题对此进行了测试,并且它似乎可行: .hb-form-table { display: flex; justify-content: space-between; } 这将做的是确保项目在一个灵活的容器中,不允许他们去下一行。 需要一些额外的CSS来确保输入字段都具有相同的填充和高度。 如果您刚接触flex-box,请参阅如何使用它的完整指南及其所有属性: https : //css-tric ...
  • 有一个名为Database Sync的Wordpress插件,它允许您在Dev,QA和Production等多个服务器上同步WP数据库。 但它不允许您同步上传的文件。 http://wordpress.org/plugins/database-sync/ 您可以使用FTP同步软件来保持上传的文件同步。 我使用WinSCP。 There's a Wordpress plugin called Database Sync which lets you sync your WP database across m ...
  • 尝试使用DIV将其分为两部分。 float:left; 第一次DIV Try to separate that in two parts using DIV. Give float:left; to first DIV
  • 我们试试看: .container_img { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; align-items: center; justify-content: center; } 和
    我不确定你是否在寻找 使用标题和HTML代码通过Wordpress编辑器进行快速修复 通过Wordpress html编辑器快速修复手动重新创建字幕代码 通过functions.php文件和wp-includes / media.php中的add_shortcode()进行永久性修复 通过CSS永久修复可能会影响所有标题。 我尽量保持你的代码不受影响
    // This should align the entire block [it work ...
  • 将它们包裹在容器中。 并使用下面的CSS