inputbox issues - looping through range twice

scorpweb

Board Regular
Joined
Jul 26, 2011
Messages
124
Hey All,

trying to format some data on multiple tabs

i've got select range selected via an input box as it varies each month. but the same range is required over 2 tabs.

I need to have the selected code to perform over both tabs 'ADL' and 'SYD'

can anyone advise why this isn't working or a workaround for it? do i need to set another rng variable for the 2nd tab? if so can i duplicate the inputbox result to this variable?

Code:
Sub percent2()

dim rng as range


Set rng = Application.InputBox(Prompt:="Range in Column I for the Month", Title:="Range Select", Type:=8)


For Each rng In rng



Worksheets("ADL").Activate
    If rng <> "" Then
rng.Value = Format((rng.Value / 100))
rng.NumberFormat = "0%"
rng.Offset(0, -1).Value = Format((rng.Offset(0, -1).Value / 100))
rng.Offset(0, -1).NumberFormat = "0%"
rng.Offset(0, -2).Value = Format((rng.Offset(0, -2).Value / 100))
rng.Offset(0, -2).NumberFormat = "0%"
rng.Offset(0, -3).Copy
rng.Offset(0, 1).PasteSpecial
End If
Next


Worksheets("SYD").Activate
    If rng <> "" Then


rng.Value = Format((rng.Value / 100))
rng.NumberFormat = "0%"
rng.Offset(0, -1).Value = Format((rng.Offset(0, -1).Value / 100))
rng.Offset(0, -1).NumberFormat = "0%"
rng.Offset(0, -2).Value = Format((rng.Offset(0, -2).Value / 100))
rng.Offset(0, -2).NumberFormat = "0%"
rng.Offset(0, -3).Copy
rng.Offset(0, 1).PasteSpecial
End If
Next
end sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe this
Code:
Sub percent2()
Dim rng As Range, myary As Variant
myary = Array("ADL", "SYD")
Sheets(myary).Select
Set rng = Application.InputBox(Prompt:="Range in Column I for the Month", Title:="Range Select", Type:=8)
For Each rng In rng
If rng <> "" Then
rng.Value = Format((rng.Value / 100))
rng.NumberFormat = "0%"
rng.Offset(0, -1).Value = Format((rng.Offset(0, -1).Value / 100))
rng.Offset(0, -1).NumberFormat = "0%"
rng.Offset(0, -2).Value = Format((rng.Offset(0, -2).Value / 100))
rng.Offset(0, -2).NumberFormat = "0%"
rng.Offset(0, -3).Copy
rng.Offset(0, 1).PasteSpecial
End If
Next rng
Sheets("SYD").Select
End Sub
 
Upvote 0
Maybe this
Code:
Sub percent2()
Dim rng As Range, myary As Variant
myary = Array("ADL", "SYD")
Sheets(myary).Select
Set rng = Application.InputBox(Prompt:="Range in Column I for the Month", Title:="Range Select", Type:=8)
For Each rng In rng
If rng <> "" Then
rng.Value = Format((rng.Value / 100))
rng.NumberFormat = "0%"
rng.Offset(0, -1).Value = Format((rng.Offset(0, -1).Value / 100))
rng.Offset(0, -1).NumberFormat = "0%"
rng.Offset(0, -2).Value = Format((rng.Offset(0, -2).Value / 100))
rng.Offset(0, -2).NumberFormat = "0%"
rng.Offset(0, -3).Copy
rng.Offset(0, 1).PasteSpecial
End If
Next rng
Sheets("SYD").Select
End Sub

Thanks Michael,

I tried it and it does select both worksheets but doesn't seem to apply the changes to any but the first Worksheet ("ADL") in this case. If i swap them around it applies it to SYD and not ADL.

:( any ideas?
 
Upvote 0

Forum statistics

Threads
1,224,416
Messages
6,178,509
Members
452,853
Latest member
philipnjk64

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