doesn't work properly

fastbuck

Board Regular
Joined
Apr 22, 2014
Messages
144
Hiall.

I put this together from bits that I found through a search. However it's not working. Can I please get some help.
Code:
Sub AAA_Move_Data_One()

Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=""

For Each cell In Range("G3:G12")
    If cell.Value = vbNullString Then
        cell.Value = Range("K9")
    Exit Sub
    End If
Next cell

For Each cell In Range("H3:H12")
    If cell.Value = vbNullString Then
        cell.Value = Range("L9")
        Exit Sub
    End If
Next cell

Range("G28").Select

ActiveSheet.Protect Password:=""
Application.ScreenUpdating = True

End Sub
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Could you give us a little more to go on? Like what the actual problem is?
 
Upvote 0
:) Thanks for your reply. I'm not too good on explanations. I have 2 columns of figures (K9:L12) - I want to be able to put an option button at each row and have the macro move those 2 figures to the first blank cells at G3:H12.

I found this worked ok, but when I added the second part it still only executed the first part.

For Each cell In Range("G3:G12")
If cell.Value = vbNullString Then
cell.Value = Range("K9")
Exit Sub
End If
Next cell

Hope this makes some sort of sense. I guess I could do it with one button for each individual cell, but I though it could be combined somehow.

Thank you
N
 
Upvote 0
It's the Exit Sub line. You probably want this:
Code:
Sub AAA_Move_Data_One()

Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=""

For Each cell In Range("G3:G12")
    If cell.Value = vbNullString Then
        cell.Value = Range("K9")
    Exit For
    End If
Next cell

For Each cell In Range("H3:H12")
    If cell.Value = vbNullString Then
        cell.Value = Range("L9")
        Exit For
    End If
Next cell

Range("G28").Select

ActiveSheet.Protect Password:=""
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Geez mate you are a genius...fair dinkum as we would say here in Oz. That works perfectly, thank you.
Narelle
 
Upvote 0

Forum statistics

Threads
1,203,620
Messages
6,056,330
Members
444,861
Latest member
B4you_Andrea

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