Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49962

Copying text from clipboard to first empty row

$
0
0
I have a 30 line text file with all lines looking like this, some separated by empty lines. All have a 'return' (CR LF) at the end.

Code:

GPX file name = tFileName = 20190706Cadgwith-Coverack-r1060-m7.3.gpx         
Track description = tTrackDescr = Cadgwith to Coverack, SWCP 2019

Date for later use =  tDatePrefix = 20190706

I have externally copied all the text to the clipboard. My VBA macro includes this code which display it in a temporary message box. (Well, most of it. Apparently there is a 1024 character limit.)

Code:

Sub Test_GetData()
    Dim objData As New MSForms.DataObject
    Dim strText

    objData.GetFromClipboard
    strText = objData.GetText()

    MsgBox strText
End Sub

But I'm struggling with the next two stages and would appreciate some help please.

1. For each line, set a VBA variable containing the part after last equal sign. Ideally, but not essential, I'd like to use a variable name identical to the string after the first equal sign. So the first line would generate a string variable called 'tFileName' with value '20190706Cadgwith-Coverack-r1060-m7.3.gpx'.

2. In the single, already open workbook 'WalkIndex.xlsm', sheet 'Target', create a new row from these variables at the end of all previous rows. So tFilename would be entered into col C, tDatePrefix into col B, etc. When my source was in another workbook I was doing it with the following code (developed with much help here):

Code:

Sub CopyCellsToWI_ToEmpty_BigEdit()
'Copy cells from a another workbook to WalkIndex.xlsm, sheet 'Target'
'====================================================================

'Set up most variables/objects
Dim nr As Long, wi As Workbook, wb As Workbook, ws As Worksheet
Set wi = Workbooks("WalkIndex.xlsm")
Set ws = wi.Sheets("Target")

'Find the first empty row (col A) in WalkIndex
    With ws
    'Find first empty row (last used + 1)
    nr = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
 
    'Copy track data to appropriate cells of WalkIndex in first empty row
   
    'Track date copied to two locations in WalkIndex: col A & col B
    'Copy to 'Date of walk' (col A)
    wb.Worksheets("Track Data").Range("B6").Copy ws.Range("A" & nr)
       
    'Copy to 'Date prefix' (col B)
    wb.Worksheets("Track Data").Range("B6").Copy ws.Range("B" & nr)

    'Duration (hhmm)
    wb.Worksheets("Track Data").Range("B10").Copy ws.Range("J" & nr)
   
    etc
   
    End With
etc
End Sub


I've attached an extract from WalkIndex.xlsm

Any assistance would be much appreciated please.
Attached Files

Viewing all articles
Browse latest Browse all 49962

Trending Articles