Can someone help me with the following queries.
I have an Excel file with four sheets - Sheet A, Sheet B, Sheet C, Sheet D
In Sheet A - contain all Formulas and Calculations.
Sheet D has the Excel VBA Button with the following Macro is created and it is being filling correctly data in Sheet B
Sub CopySelectedColumnToNxSh()
"CopySelectedColumnToNxSh Macro"
Sheets("A").Range("E1:E14").Copy
Sheets("B").Range("A530").End(xlUp).Offset(1, 0).Range("A1").PasteSpecial xlPasteValues, Transpose:=True
End Sub
I would like to add another function to the button that can executes the following
Copy values from Sheet A to Sheet C where there is a table with Header (Months - Jan to Feb) and occupied first Column A. I would like to copy the values under each Month Column from this range B2:M11 without overwriting the previous one
I am trying with the following code but I'm not able to set it to move to new column
Sub Year_1()
Sheets("A").Range("E1:E10").Copy Destination:=Sheets("C").Range("B2")
End Sub
Can a logic be added for the button that for each 12 Clicks (Sheet C copy range is filled) it creates another sheet in the table.
Related
I have an ID and Name column in sheet A and in sheet B I have an ID column and an empty column
what I want to do is to fill the empty column with values from the Name column in sheet A where both the ID columns are matched
here is what I want to do in MySQL statement
select SheetA.Name from SheetA join SheetB on SheetA.id = SheetB.id
can someone help translate this to excel code?
Refer to screenshots when interpreting the ranges (which will require modification to suit your specific needs / Excel data list positioning)...
VB code:
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveCell.Formula2R1C1 = _
"=INDEX('67650244 (2)'!R4C3:R7C3,MATCH('67650244'!R4C2:R7C2,'67650244 (2)'!R4C2:R7C2,0))"
Range("C5").Select
ActiveWindow.SmallScroll Down:=-3
End Sub
Screenshots
Sheet 1 (entitled "67650244"):
Sheet 2 (entitled "67650244 (2)"):
This assumes the source values you're looking up from are contained with the 2nd sheet (i.e. "67650244 (2)"), and the index/match function "places" the relevant ID/lookups into Sheet 1 (i.e. "67650244"). Further, the "activecell" is simply cell "C4" in sheet 1 (the function in the VB code above will insert the response/'looked-up' values as an array to fill all values adjacent to those in column B of this sheet (assuming a successful lookup, if not, then it will display "#Value!" next to the relevant Lookup value that couldn't be found in sheet 2....
Note: VB using "Row/Column" referencing when using a function like this, where "R1C1! simply refers to cell A1 in excel. To decipher this more easily for writing up the applicable version of code for your case, you can go to "Tools, Options, Formula" in the left had pane (within Excel, not VB), and then select "R1C1 Reference Style" box, per screenshot below:
You can always change this back later (deselect the option) as desired the same way.
Note: it would be far easier / more convenient to just use the index(range to return, match(value to lookup, range to lookup, 0)) method within excel as opposed to within VB - but this depends on desired functionality of your setup/circumstances/excel model/etc.
I have a working spreadsheet with lists of items. One field could have 1 of 14 descriptions. I thought creating a macro would be quicker than manually going to a separate sheet and copying and pasting the desired description every time.
I am totally new to this, but was able to create a macro grabbing data in cell A1 in one sheet and adding that data to cell S3 in another sheet - see code below. (Each description has its own sheet with data in cell A1) My question is, how to move onto the next row and cell S4. Thanks in advance!
Sub Range_Copy()
Worksheets("Used Single Items Returns").Range("A1").Copy Worksheets("Gopher Items CSV Test").Range("S3")
End Sub
If you just want to copy into Col S on the selected row:
Sub Range_Copy()
Dim r
Set r = Selection.Cells(1).entirerow.range("S1") 'relative to row, not sheet
Worksheets("Used Single Items Returns").Range("A1").Copy r
End Sub
I need some help for my Excel sheet,
I have the first sheet and this is blank
and on the seconde sheet i have a list and in the column D i can change the value starts from 1.
And when i changed in the column a cell then it should copy the row to the first sheet.
thanks
Regards
It is not clear for me what you want to do. If you want VBA to copy the row automatically, you should go to the module of the corresponding Worksheet in the VBA editor (in the list of the Wroksheets on the left, just double-click the Worksheet to open up the module associated with it). After that, write an event handler:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
ActiveSheet.Rows(Target.Row).Copy Worksheets("Sheet1").Rows(whichRowYouNeed)
End If
End Sub
you should also write a routine to determine the 'whichRowYouNeed'
It may be the end of the filled range on Worksheet1
Hey sorry for my bad statement, i try it again :)
The first sheet is blank,
The Second sheet is that:
When i add a number in column D then I want to copy this row, in that case row 8, copy to the first sheet starting from row 5.
I hope now it is better to understand
Scenario: I can't post the actual workbook due to sensitive materials but I'll explain it as best as possible.
Each Sheet is divided into branches i.e.: Sheet2 is Branch 2, Sheet3 is Branch 3 and so on.
For each sheet the column are the same.
Column A has the branch number in it.
Column B has irrelevant information so i just hide that column.
Column C has a system number (specific to each account.
Intention: I want to create another sheet called CallOuts.
I want to copy some rows (from various branches) and paste them onto the 'Master sheet' (CallOuts) I can work on the CallOuts sheet instead of going to each branch. So that whenever I edit a cell it will also update/change that exact same cell in the branch sheet and vise versa with the master sheet.
Problem: I know MS Exccel has a "Paste Special" function where it adds the cell. The problem with that is it links the cell# so if I sort the Master sheet it will replace the row into the wrong branch sheet.
E.g.: If System# J112 is in branch 2 sheet, row 2 and I have the link pasted in Row 4 in the master sheet, if I make updates on the Master sheet and then re-sort it and the System# now moves to Row 2 (on the master sheet) whatever is in Row 4(on the master) will now be in Row 2, Branch 2 sheet.
I was thinking maybe a macro where I could copy and paste the entire row from the master sheet. Do some type of case selection to check which branch is in column A and then find the same system # on the branch sheet then paste the whole row.
My VBA level is novice at best so any help would be appreciated.
OK, So I saw your attempt below. I am not sure how your code works but it seems like you were on the right track. However, I don't think the Case syntax is appropriate for this situation. You simply need a macro that will read what is in your "CallOuts" sheet and use that data to update your individual branch sheets. This macro should work for you:
Sub UpdateRecordsFromMasterSheet()
Dim wksht As Worksheet
Dim wkb As Workbook
Dim row As Range
Dim Row_to_Update As Range
Dim sysnum As Variant
Set wbk = ThisWorkbook
Application.ScreenUpdating = False
For Each row In Sheets("CallOuts").UsedRange.Rows
row.EntireRow.Copy
sysnum = row.Cells(1, 3).Value
For Each wksht In ActiveWorkbook.Worksheets
For Each Row_to_Update In wksht.UsedRange.Rows
If Row_to_Update.Cells(1, 3).Value = sysnum Then
Row_to_Update.PasteSpecial
End If
Next Row_to_Update
Next wksht
Next row
Application.ScreenUpdating = True
End Sub
This assumes you have your system number in column "C". So here is what I am imagining: Each time you assign an employee a bunch of rows - your employee updates those rows - and then you paste that data back into the "CallOuts" sheet. Then you run this macro and it will update the individual branch sheets based on what is in the "CallOuts" sheet.
If your a visual person here is how it will look:
Here is the updated callouts sheet:
Here is how the branches will look before the macro:
Here is the updated branch after the macro runs:
Try it out and let me know how it works. Note: this is just a start to show you how to do something like this - you could make this process more efficient by having the macro loop through the actual workbooks that the employees submit to you so you wouldn't have to copy and paste the data into your "CallOuts" sheet every time. Good Luck.
I'm new to the visual basics language and would like some help in writing some codes. So I'm trying to write a program that imports data from a spreadsheet and shifts current data over. So I have a spreadsheet file with 3 sheets. I would first delete the data in the third and last sheet, then cut and copy the data from the second sheet over to the third sheet and the first to the second. and then prompt the user to select a data file to import to the first sheet. How do I go about doing this ????
Thanks
You can access each cell by using
Cells(row,column)
Where the row and column are both numeric. You can set the values like this
Cell(row,column) = "This is a new value"
You can access the values like this
aString = cells(row,column)
If you want to copy data from one worksheet to another, this code will copy the first twenty six columns and rows from worksheet 2 to worksheet 3...
dim row as integer
dim column as integer
For column = 1 to 26
For row = 1 to 26
'Copy worksheet 3 value to worksheet 2's value
Worksheets(3).cells(row,column)=Worksheets(2).cells(row,column)
'Clear worksheet 2's values
Worksheets(2).cells(row,column)=""
Next
Next
You could simply delete the third sheet by executing:
Application.DisplayAlerts = False
ActiveWorkBook.Sheets(3).Delete
Then insert a new sheet and place it before Sheet 1 and 2
ActiveWrokBook.Sheets.Add Before:=ActiveWorkBook.Sheets(1)
ActiveSheet.Name = "The New Name of your newly inserted sheet"
Then fill the sheet with any data that you may want to. You did not include any details in your question about what is the source of the data, so I guess, you already know about that.