VBA Macro button to Copy from a cell (M15) to the next available blank cell in a range of cells (D28-D77)

Yurop

New Member
Joined
Dec 5, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am struggling to write a piece of code to copy a cell to the next available (blank) cell in a range (D28-D77).
My worksheet reads from a CSV that i import into a second worksheet and then runs a whole bunch of calculations, from which i get the output i am after in a cell (M15).
I need to do this again and again for a number of CSV's. What i would like to do is to not have to cut and paste this value manually every time i do my calcs on a CSV.

Any help would be appreciated.
1670299899717.png
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Your button "Import CSV" should be linked with a Macro.
You should add some code into the Macro for the two purposes:
A. copy cell "M15" to the most upper blank cell of D28-D77.
B. loop to open CSV files and run the Macro.

Purpose A is easier like this:
VBA Code:
    Range("M15").Copy
    'Be sure "D78" must be blank
    Range("D78").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues

Purpose B. mm..just try it.
VBA Code:
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "CSV files", "*.csv"
        .Show
        'then pick your CSV files
        For lngCount = 1 To .SelectedItems.Count
            myFileName = .SelectedItems(lngCount)
            'Here is your Macro of "Import CSV"
            'And you should put "myFileName" into the right place of the code.
            '............
            'put the Purpose A code          
           Range("M15").Copy
           'Be sure "D78" must be blank
           Range("D78").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
        Next lngCount
    End With

Hope this help.
 
Last edited:
Upvote 0
Awesome, thanks for your help!
I got that working now.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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