Command Button to change a Cell

Tech1_uk

New Member
Joined
Sep 22, 2018
Messages
17
Hi all,

I've set up a simple button to change a cell value from another cell,

Code is

VBA Code:
Private Sub CommandButton1_Click()

Sheets("Sheet1").Range("G6").Value = Sheets("Sheet2").Range("E5").Value

End Sub

Now I only want to change G6 if it matches a a set criteria, in this case "No" if it it then any other text then don't change the value.
Once this is working I then want to use the range G6:G25 to do the same

Any ideas?

Many thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I've managed the first part but I can't repeat this over a range of cells

I'm using the following

VBA Code:
If Range("G6").Value = "No" Then Sheets("Sheet1").Range("G6").Value = Sheets("Sheet2").Range("E5").Value

For Cell G7 and onwards I'm having to repeat each line

Code:
If Range("G7").Value = "No" Then Sheets("Sheet1").Range("G7").Value = Sheets("Sheet2").Range("E5").Value

Has to be an easy way to do this ???
 
Upvote 0
VBA Code:
Dim c As Range
For Each c In Range("G7:G25")
    If c = "No" Then c = Sheets("Sheet2").Range("E5").Value
Next c
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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