Entering a number via a macro

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
385
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Barrie Davidson

MrExcel MVP
Joined
Feb 10, 2002
Messages
2,330
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,
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,886
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,160
Messages
5,768,530
Members
425,480
Latest member
br400821

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
Top