Loop trough two ranges

Excelmax1

New Member
Joined
Aug 11, 2022
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I need help in looping the code below trough my named range or just skip blank rows. Below code works fine until it should skip rows which should not contain textbox value.
My textboxes for this code starts at 58 and runs trough 66. But the value from theese textboxes should be pasted to cells D8:18 where C14 and C15 are empty and should be skipped. Notice that the empty cells are in C8:C18 but the value should be pasted in D8:18.

Im planning on expanding this code for about 150 textboxes so writing them all out is not an option. Do anybody know a solution, it could be to skip blank rows in the range or use a named range wich i couldnt get to work.

Any help is appreaciated


Basically this checks for input in textbox, if empty then nothing happens when I press on the "save button". Otherwise the textbox value are pasted to the specified range in my spreadsheet.

The "RR2 - 50" refers to column D and row "RR2=58-(50)=8" D8
But when some cell in C8:C18 is empty i would like the textbox value to skip that row and try the next row in that range and when not empty, paste the value in range D8:D18.

It works fine until D13 but then theres no value in B14 and B15 but below code doesnt recognize that and keeps pasting textbox value in row 14 and 15 isntead of skipping these and pasting in 16-18

Code:

Dim RR2 As Integer
For RR2 = 58 To 66

If Controls("TextBox" & RR2).Value = "" Then
Else

Worksheets("Rabattsatser").Range("D" & RR2 - 50).Value = Controls("TextBox" & RR2).Value
End If

Next RR2
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Maybe something like this.

VBA Code:
        With Worksheets("Rabattsatser").Range("D" & RR2 - 50)
            If Controls("TextBox" & RR2).Value <> "" And Trim(.Offset(0, -1).Value) <> "" Then
                .Value = Controls("TextBox" & RR2).Value
            End If
        End With


(Tip: when posting code, please try to use 'code tags' to format the code as I have done above
as it makes the code easier to read.)
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,039
Members
452,542
Latest member
Bricklin

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