Want to write in VBA, If cell is not blank, do x

Badnames

Board Regular
Joined
Jun 12, 2007
Messages
211
I want to make it so my if statement will work if the cell is not blank. Currently my if statement only works if the cell is equal to a specific value. In this case the value is ####

If Range("B" & i) = "####" Then
Worksheets("####").Activate
Sheets("####").Range("A" & (13 + ####Count)) = Sheets("Input").Range("AD" & i)
Sheets("####").Range("D" & (13 + ####Count)) = Sheets("Input").Range("P" & i)
Sheets("####").Range("E" & (13 + ####Count)) = Sheets("Input").Range("U" & i)
Sheets("####").Range("F" & (13 + ####Count)) = Sheets("Input").Range("O" & i)
Sheets("####").Range("G" & (13 + ####Count)) = Sheets("Input").Range("U" & i)
Sheets("####").Range("H" & (13 + ####Count)) = Sheets("Input").Range("F" & i)
Sheets("####").Range("I" & (13 + ####Count)) = Sheets("Input").Range("S" & i)
Application.CutCopyMode = False
####Count = ####Count +

So basically if range("B"&i) is not blank, do the copy and paste function, rather than only doing it when it is equal to a specific value.
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
This looks like it is for checking if the cell is empty, but I want to do the opposite. If the cell has any value other than blank, I want the formula to work.
 
Upvote 0
If Not IsEmpty("B" & i) Then

Worksheets("Summary").Activate
Sheets("Summary").Range("A" & (12 + Summarycount)) = Sheets("Input").Range("B" & i)
Sheets("Summary").Range("C" & (12 + Summarycount)) = Sheets("Input").Range("Y" & i)
Sheets("Summary").Range("D" & (12 + Summarycount)) = Sheets("Input").Range("Z" & i)
Summarycount = Summarycount + 1

End If

I tried this code, but it is still copying where the cells are blank, as well as taking an extremely long time to process. Do you know how I could improve it?


Edit* O yeah, this is all part of a loop. i is an integer to keep count of the row in the inputs sheet.
 
Upvote 0
If you have formuals returning "" in col B then

Code:
If Range("B" & i ) <> "" Then
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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