PDA

View Full Version : Solved: Selection reference



NiklasBech
03-31-2013, 04:57 AM
Hello

Im trying to copy from a selection lets call it s1 to another selection lets call it s2, s2 is selected by inputbox type:=8..
I run through s1 with a for each loop, and then i want to replace the value's in s2 with s1, how can i do this ? Can i referer to each cell in a selection with a command?

And when i use inputbox type:=8 is it possible to fix/suggest a size for my selection?

Best Regards Niklas

mdmackillop
03-31-2013, 05:18 AM
Why copy one cell at a time? Is the target to be the same size as the source? If so, you need only pate to the first cell of S2.

NiklasBech
03-31-2013, 05:26 AM
Because i want to use a function on each cell in the selection.. :)

Sub Form()
Set R = Application.Selection
Dim i As Integer
i = 0
For Each Celle In R.Cells
If typeD = True Then
If Celle.HasFormula Then
Dim rg As Range
Dim SubA As Integer
Set rg = Range(Celle.Address)
SubA = Celle.Column + 1
If Cells(Celle.Row, SubA).Value = 0 Then
Cells(Celle.Row, SubA) = "=Udregn(rg)"
End If
End If
Else
If Celle.HasFormula Then
If i = 0 Then
On Error Resume Next
Set userInput = Application.InputBox("Select an area", Default:=Selection.Address, Type:=8)
End If
'here i want to use a function on each celle in R, and place it in userinput
Else
MsgBox ("No Formula here")
End If
End If
i = i + 1
Next Celle
End Sub

mdmackillop
03-31-2013, 07:58 AM
Not sure if this is what you are after. It uses a Userform to allow you to select a range and size.