Macro to Copy Column, Open Existing Document, Paste & Save?
Closed
sarahzim
Posts
5
Registration date
Wednesday April 8, 2015
Status
Member
Last seen
April 15, 2015
-
Apr 8, 2015 at 02:44 PM
sarahzim Posts 5 Registration date Wednesday April 8, 2015 Status Member Last seen April 15, 2015 - Apr 15, 2015 at 05:13 PM
sarahzim Posts 5 Registration date Wednesday April 8, 2015 Status Member Last seen April 15, 2015 - Apr 15, 2015 at 05:13 PM
Related:
- Macro to Copy Column, Open Existing Document, Paste & Save?
- Save as pdf office 2007 - Download - Other
- Save audio from messenger - Guide
- Elden ring save location - Guide
- How to save ping command in notepad - Guide
- How to automatically save photos from messenger to gallery - Guide
2 responses
MaxStart
Posts
339
Registration date
Tuesday March 3, 2015
Status
Moderator
Last seen
July 3, 2015
69
Apr 8, 2015 at 04:57 PM
Apr 8, 2015 at 04:57 PM
you'll be amazed to know how much you can do with VB, but to be honest I almost fell asleep reading the explanation,
what I suggest is that you make a very light version of your excel file or even better you can make a small example for us with a fake customer and sales files, upload it to some sharing host, post it here, and then I can view it and start a combo about it with you.
Good luck.
what I suggest is that you make a very light version of your excel file or even better you can make a small example for us with a fake customer and sales files, upload it to some sharing host, post it here, and then I can view it and start a combo about it with you.
Good luck.
MaxStart
Posts
339
Registration date
Tuesday March 3, 2015
Status
Moderator
Last seen
July 3, 2015
69
Apr 15, 2015 at 04:50 PM
Apr 15, 2015 at 04:50 PM
Hello,
time to get some work done for you.
what I will provide now is basically all the major coding and planning for this situation, but you HAVE to adapt it your needs.
this will grab data from Today workbook, insert it as wanted in the inventory workbook, put it in the customer workbook, save as customer-mm-dd-yyyy.csv.
OK, let's get started,
The user UI will look like this
download these two files: UserForm1.frm, UserForm1.frx from here and put them in the same folder then open inventory workbook, press Alt+F11 to open Visual Basic Editor and follow the pictures to import the user form to your workbook:
right click and choose as shown:
import the UI
now you need to insert a module that will contain the macro to show the UI:
the code to show the UI:
time to get some work done for you.
what I will provide now is basically all the major coding and planning for this situation, but you HAVE to adapt it your needs.
this will grab data from Today workbook, insert it as wanted in the inventory workbook, put it in the customer workbook, save as customer-mm-dd-yyyy.csv.
OK, let's get started,
the main thing is that you need to have the files in the same folder in-order for this to work.
- the inventory file will be an empty workbook and will be filled as needed by you, all the codes and user UI will be stored in it, so it's going to be an ".xlsm" file.
The user UI will look like this
download these two files: UserForm1.frm, UserForm1.frx from here and put them in the same folder then open inventory workbook, press Alt+F11 to open Visual Basic Editor and follow the pictures to import the user form to your workbook:
right click and choose as shown:
import the UI
now you need to insert a module that will contain the macro to show the UI:
the code to show the UI:
Sub ShowMe() UserForm1.show End Sub
Add customer items to ComboBox1, and Add items to the List box from Today.xlsx when UserForm1 initialize
Option Explicit Private Sub UserForm_Initialize() 'Add customer items to ComboBox1 Dim m As Long m = 1 With ComboBox1 .Clear Do While Cells(1, m).Value <> "" .AddItem (Sheet1.Cells(1, m).Value) m = m + 3 Loop End With '========================================================= ' 1- Open the source workbook as ReadOnly ' 2- extract the needed data ' 3- close the source workbook without making any changes ' 4- populate the extracted data into the listbox. '========================================================= Dim ListItemsR As Variant, i As Integer, ListItemsC As Variant Dim SourceWB As Workbook Dim j As Long j = 1 With ListBox1 .Clear Application.ScreenUpdating = False Set SourceWB = Workbooks.Open(ThisWorkbook.Path & "\Today.xlsx", False, True) Do While SourceWB.Worksheets(1).Cells(j, 1).Value <> "" j = j + 1 Loop ListItemsR = SourceWB.Worksheets(1).Range(Cells(1, 1), Cells(j - 1, 1)).Value ListItemsC = SourceWB.Worksheets(1).Range(Cells(1, 4), Cells(j - 1, 4)).Value SourceWB.Close False Set SourceWB = Nothing ListItemsR = Application.WorksheetFunction.Transpose(ListItemsR) ListItemsC = Application.WorksheetFunction.Transpose(ListItemsC) For i = 1 To UBound(ListItemsR) .AddItem ListItemsR(i) .List(i - 1, 1) = ListItemsC(i) Next i Application.ScreenUpdating = True End With End Sub
Inserting selected items in Inventory workbook from the list box
Private Sub Go_BTN_Click() Range("b:b").Value = "" Range("c:c").Value = "" Dim i, j, m, d As Integer i = 0 j = 1 m = 1 Do While Cells(1, m + 3).Value <> "" If Cells(1, m).Value = ComboBox1.Value Then more: Do With ListBox1 If ListBox1.Selected(i) Then Cells(j, m + 1).Value = .List(i, 0) Cells(j, m + 2).Value = .List(i, 1) j = j + 1 End If End With i = i + 1 Loop Until i = ListBox1.ListCount ComboBox1.Value = "" ListBox1.MultiSelect = fmMultiSelectSingle ListBox1.MultiSelect = fmMultiSelectMulti Exit Sub End If m = m + 3 Loop GoTo more End Sub
exporting data
Private Sub Export_BTN_Click() '======================================================================== Dim SRS As Workbook, CSTMR As Workbook, FilePath As String '= FilePath = ThisWorkbook.Path & "\Customer1Template.csv" '= Set SRS = Workbooks("InventoryTemplate.xlsm") '= define Workbooks Workbooks.Open (FilePath) '= open Customer1Template Set CSTMR = Workbooks("Customer1Template.csv") '= minimize it CSTMR.Windows.Application.WindowState = xlMinimized '= '======================================================================== Dim j As Integer '= j = 1 '= Do Until CSTMR.Sheets("Customer1Template").Cells(j, 11).Value = "" '= define search range in j = j + 1 '= Customer1Template.csv Loop '= j = j - 1 '= '======================================================================== Dim i As Integer, Fitch As Range, SRCHrng As Range, Cell As Range i = 1 Application.ScreenUpdating = False Do Until SRS.Sheets("sheet1").Cells(i, 2).Value = "" Set Fitch = SRS.Sheets("sheet1").Cells(i, 2) Set SRCHrng = CSTMR.Sheets("Customer1Template").Range(Cells(1, 11).Address, Cells(j, 11).Address) Set Cell = SRCHrng.Find(Fitch) If Not Cell Is Nothing Then CSTMR.Sheets("Customer1Template").Cells(Cell.Row, Cell.Column + 3).Value _ = SRS.Sheets("sheet1").Cells(i, 3).Value End If i = i + 1 Loop Application.DisplayAlerts = False With CSTMR .SaveAs ThisWorkbook.Path & "\Customer1Template-" & Format(Date, "mm-dd-yyyy") & ".csv" .Close End With Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
Other code are self-explained
Private Sub Clear_BTN_Click() ListBox1.MultiSelect = fmMultiSelectSingle ListBox1.MultiSelect = fmMultiSelectMulti End Sub Private Sub CLRdata_Click() Range("b:b").Value = "" End Sub Private Sub ComboBox1_Change() If ComboBox1.Value = "" Then Go_BTN.Enabled = False Else Go_BTN.Enabled = True End If End Sub Private Sub SelectAll_Btn_Click() Dim r As Integer For r = 0 To ListBox1.ListCount - 1 ListBox1.Selected(r) = True Next r End Sub
sarahzim
Posts
5
Registration date
Wednesday April 8, 2015
Status
Member
Last seen
April 15, 2015
Apr 15, 2015 at 05:13 PM
Apr 15, 2015 at 05:13 PM
OH my gosh! Thank you so much! I cant imagine how much work went into that!
I've obviously not yet put it together yet, but I will let you know how it goes.
Thank you thank you thank you.
I've obviously not yet put it together yet, but I will let you know how it goes.
Thank you thank you thank you.
Apr 8, 2015 at 11:15 PM
https://drive.google.com/drive/folders/0B9RdeR30sXv1SF8yLXJ5cnBMeDQ?usp=sharing
"Today.xlsx" is a file that I would download from my warehouse's website. From there, in my perfect world, I'd start a macro that would:
1. Find and replace all spaces in column A with nothing (delete spaces).
2. Open the files "Inventory Template.xlsx", "Customer1Template.csv", "Customer2Template.csv" and "Customer3Template.csv"
3. In "Inventory Template", Copy Column C, and paste values in Column N of "Customer1Template", In "customer1template", select all, copy, paste values. Save file as "Customer1mmddyy.csv"
4. Repeat Step 3 for Column F of "Inventory template" into Column N of "Customer2Template" and Column I "Inventory Template" into "Customer3Template".
5. If possible, close all the files
All files (templates and outputs) can be in the same directory. I:Ideas\\Ecommerce\Inventories
Apr 9, 2015 at 04:17 PM
Column A - Item Number
Column B - Item Description
Column C - Warehouse Location
Column D - Quantity
The only columns that I need to use are A&D, the rest just come with the report.
Apr 9, 2015 at 11:42 PM
but don't worry I like working out my little brain with some VB
OK,
I will be providing a full tutorial on how to transfer data between workbooks using a friendly User Interface, which we will build and populate it's contents accordingly.
this sounds like fun but it needs a day or two cause I just have a bit more free time.
here's a shot from the primitive UI populated with some data.
Apr 11, 2015 at 09:39 PM