Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

excel - Using InputBox for copying and transposing non-continguous cells

   Public Sub TaxBenefitPasteG11()

    Dim FileToOpen As String
    
    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng3 As Range
    Dim rng4 As Range
    Dim rng5 As Range
    
    
    'Select range from user'

    Set rng1 = Application.InputBox("1", "Cash benefit", Type:=8)
    Set rng2 = Application.InputBox("2", "Direct taxes+NIC", Type:=8)
    Set rng3 = Application.InputBox("3", "Indirect taxes", Type:=8)
    Set rng4 = Application.InputBox("4", "Benefits in kind", Type:=8)
    Set rng5 = Application.InputBox("5", "Final income", Type:=8)
    
    Range("rng1, rng2, rng3, rng4, rng5").Select
    
    Selection.Copy
    
    Windows("For Analysis .xlsm").Activate
    
    'Go up to certain range until it finds the data, and then offset paste by one row'
    
    Range("B65536").End(xlUp).Offset(1, 0).Select
    
    'Transpose the selected copy object'
    
    
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    
        
End Sub

Basically, instead of trying to copy and paste manually from another worksheet, and then transpose; I am trying to use inputbox however the error occurs at Range("rng1,rng2...) and gives:

Method range of object_Global failed

Any idea how to add non-continguous cells into Range().Select?

question from:https://stackoverflow.com/questions/65944339/using-inputbox-for-copying-and-transposing-non-continguous-cells

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...