Error 1004

MAND7841

New Member
Joined
Jan 30, 2017
Messages
3
I am trying to create a column "H" that will display the values in column F unless F is empty. In such a case, the value from column E will be entered into column H, however I am new to using vba and am not sure how to fix this macro as it continues to fail on the first line "If Range("Fi").Value = Empty Then".
Any advice would be greatly appreciated!

Sub AdditionalColumn()
Dim i As Integer
i = 2


Do:
If Range("Fi").Value = Empty Then
Range("Hi").Value = Range("Ei").Value
Else: Range("Hi").Value = Range("Fi").Value

End If


i = i + 1

Loop

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Welcome to the Board!

It is important to note that anything between double-quotes is treated as literal text. To incorporate the variable i, you would do it like this:
Code:
[COLOR=#333333]Range("F" & i)[/COLOR]
 
Upvote 0
@Joe4 ,

Thank you for your reply!
I tried what you suggested and now I am getting an error that says:
"Run-time error '424':
Object required"
 
Upvote 0
Can you post your new code?

Also, be sure that there is an end to your loop, so you don't get caught in an infinite loop!
You cannot tell it to keep adding one without a stopping point.
We can help you with that if you can tell us the logic of how far down this should go.
 
Last edited:
Upvote 0
@Joe4 ,
How would I end the loop whenever the data is complete?

Here is the updated code:

Sub AdditionalColumn()
Dim i As Integer
i = 2


Do:
If Range("F" & i).Value.Select = Empty Then
Range("H" & i).Value = Range("E" & i).Value
Else: Range("H" & i).Value = Range("F" & i).Value

End If


i = i + 1

Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,924
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top