I am trying to merge two cell of excel row, it works but when I insert a new column and than trying to merge row cell including new column cell it does not and I required to insert a new column what should I do?
Range rgSum = UsedArea.Cells[i, cellnum];
rgSum.EntireColumn.Insert();
Range rgSum2 = UsedArea.Cells[i,cellnum+1];
Range RgFinal = sheet.get_Range(rgSum, rgSum2);
RgFinal.Merge();
Related
I am working on a macro to clean up exported data from one application to upload it into another. I'm new to vba, but not programming, relatively.
I was hoping to get this out of it:
Set the range equal to the last row of column B
Insert the Formula2 = "=B1&""-""&C1" into column AS, but only down to the range of column B's last cell
I found a post suggesting this to set the last row and use it for range, but i'm unsure how to tie it into the rest of my script
myLastRow = Cells(Rows.Count, "B").End(x1Up).Row
This code works, but the current range spits it out against the entireity of the AS column, and adds a "-" to everything after columns B and C are empty.
Worksheets("export-data").Range("AS:AS").Formula2 = "=B1&""-""&C1"
Worksheets("export-data").Range("AS:AS").Copy Worksheets("Acumatica").Range("G:G")
I'm hoping to just insert that Formula in a range of AS equal to populated cells in column B
in this picture, the data in column I and R are both formulas. I want to write a code to have the formula in column I paste AS VALUES if there is an asterisk in the same row of column R and do nothin if it is blank. I need to do this for rows 9:44.
I'm new to using VBA and need to copy data from a range of cells on one worksheet to another worksheet. I need to copy a column of cells and paste it into a row of cells e.g. A1:A4 to A1:D1. This is the code i'm using but it doesn't work the way i need it too.
Sub Draft()
Worksheets("Material Check").Range("B3:B6").Copy _
Destination:=Worksheets("Archive").Range("A2:D2")
End Sub
Also I need the data thats being copied over to be added to the bottom of the table on the archive sheets and i'm not sure how to do this.
Without Excel Tables
This is a bit of an odd way to do it but if you have a lot of cells to do, it's possibly faster than copy/paste special:
ThisWorkbook.Worksheets("Archive").Range("A2:D2").Formula = "=INDEX('Material Check'!$B$3:$B$6,Column())"
ThisWorkbook.Worksheets("Archive").Range("A2:D2").Value = ThisWorkbook.Worksheets("Archive").Range("A2:D2").Value
The first line populates the destination range with a formula that pulls the data from the source, using INDEX/COLUMN to transpose the result.
The second line simply converts the formula to hard values.
EDIT - Solution to copy the values to the bottom of the list
Using Excel Table
To do this you will need to go to "Insert" --> "Table".
''Get a reference to your destination table
Dim Tbl1 As ListObject
Set Tbl1 = ThisWorkbook.Sheets("Archive").ListObjects("Table1") ''Change these to your destination sheet/table names
''add a new row to the table
Dim Newrow As ListRow
Set Newrow = Tbl1.ListRows.Add
''populate the new row
With Newrow
.Range(Tbl1.ListColumns("Column1").Index) = ThisWorkbook.Worksheets("Material Check").Range("B3") ''change these to your destination column name and your source sheet/ranges
.Range(Tbl1.ListColumns("Column2").Index) = ThisWorkbook.Worksheets("Material Check").Range("B4")
.Range(Tbl1.ListColumns("Column3").Index) = ThisWorkbook.Worksheets("Material Check").Range("B5")
.Range(Tbl1.ListColumns("Column4").Index) = ThisWorkbook.Worksheets("Material Check").Range("B6")
End With
I need some help dragging a string ("Decliners") down a column in excel. I know how to do this if I knew what cell was my starting point, but I first have to find the first blank row in my data set. Once I've found my first blank row, I need to drag my string down from there in column C3. This string is being dragged down just one column. I also don't know the range of this data set, given that it is dynamic.
Essentially I just need to recreate the action of double clicking the bottom right of the cell and the word "Decliners" fill to the bottom of the data set.
Code to select the first blank cell in worksheet:
Dim Pastesheet As Worksheet
Dim Decliners As String
Decliners = "Decliners"
Set Pastesheet = Worksheets("Ent Gainers_Decliners")
Pastesheet.Range("C3").End(xlDown).Offset(1, 0).Select
'Where I need the word "Decliners" dragged down from the cell selected
With Pastesheet
.Range(.Range("C3").End(xlDown).Offset(1),.Cells(.Rows.Count,4).End(xlUp).Offset(,-1)).Value = Decliners
End With
This piece of code will set the value of the variable Decliners from the row after the last data set from Range C3 down until the last corresponding row of used data in column D for column C.
In Microsoft Excel, I have two columns in a sheet. The first column has values like B2,A13,BB125 and the next column has some number values like 12,569,78.
I want to find the cell from the first column in another sheet and to that cell add the value from the second column.
Does anyone know how to do that?
You can retrieve the value from the cell in column A and pass it to Range() to address the cell in your other sheet.
For example:
' Use A1 as an example...
Dim r As Range
Set r = Range("A1")
' Use A1's value to address a cell on Sheet2 and assign the value from B1...
Sheet2.Range(r.Value).Value = r.Offset(, 1).Value