Using a Dashboard to copy particular rows in a particular columns and pasting them into a different excel document [closed]

StackOverflow https://stackoverflow.com/questions/21427941

  •  04-10-2022
  •  | 
  •  

質問

In my excel spreadsheet I have a master which basically controls everything. In this master I have a page which allows me to select an xlsx file, then in a drop down it allows me to select which sheet in that chosen file that I want to use. [This part is working perfectly however...]

What i am struggling with is the following, The user must be able to stipulate which row the data starts and which row the data end and what column this data is in

example:

Row in which data starts 7 Row in which data ends 25 Column of the data G Column of the Data code D

Using this information, i need excel to extract that data and copy it to another spreadsheet that the user has selected and merge them together

Column to input data H Title of column (the code must name it with the input of the user) TITLE Column of the data code E

When merging the data it must match the data to the "Data Code"

Thanks in advance

役に立ちましたか?

解決

It sound as though you are asking us to design your program.

  • The user must be able to stipulate which row the data starts and which row the data end and what column this data is in. Example: "Row in which data starts 7 Row in which data ends 25 Column of the data G Column of the Data code D.

  • Another spreadsheet (workbook?) that the user has selected.

Only you know what your users will find convenient and what will match your existing code. Below I show one method of selecting a range that you might like.

  Option Explicit
  Sub Test()

  Dim CopyRange As Range
  Dim reply As Long

  Do While True
    Err.Clear
    On Error Resume Next
    Set CopyRange = Application.InputBox(Prompt:="Select ranges to be copied", _
                                         Type:=8)
    On Error GoTo 0
    If CopyRange Is Nothing Then
      reply = MsgBox(Prompt:="Do you wish to exit without copying a range?", _
                     Buttons:=vbYesNo)
      If reply = vbYes Then
        ' User wants to exit
        Exit Sub
      End If
      ' Loop for another go
    Else
      ' User had entered a valid range
      Exit Do
    End If
  Loop

  Debug.Print CopyRange.Address

  End Sub

You tell us that you have already opened another workbook so you know how to work across multiple workbooks.

The easiest command, in my view, for copying data is:

SourceRange.Copy Destination:=TopLeftCellOfDestinationRange

The above should give you a start on the next sections of your macro. If you have problems come back with specific questions about code that does not work as you require. Please don't provide a list of vague requirements.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top