Entering a number via a macro

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
Hi,

I need a macro that says something like:

if cell g3= blank and then enter nothing in cell e3
if cell g4 is not blank then enter "4" in cell e4 etc

all the way through for rows 1-65536.

Basically if cell gx is blank then do nothing. if cell gx is not blank then enter the number 4 in ex (where x is the row number)

Jay
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
Dim LastRow As Long

LastRow = Range("G65536").End(xlUp).Row
Range("G1:G" & LastRow).AutoFilter Field:=1, Criteria1:="<>"
Range("H1:H" & LastRow).SpecialCells(xlCellTypeVisible).Value = 4
Range("G1:G" & LastRow).AutoFilter

Best regards,
 
Upvote 0
Another macro:

Code:
Sub MyMacro()
    
    Dim cell As Range
    For Each cell In Range("G1:G65536")
        If Len(cell) > 0 Then cell.Offset(0, -2) = 4
    Next cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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