I want to copy data from sheet "summary" row A44 (fixed row with dynamic data with formula) to sheet18 (row A3), A1 and A2 are header; i have below vba code and manage to do so. I would like to copy and paste the data as value (like Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False), so that the data will convert to absolute number, anyone how to edit the code?
Sub COPY_SUMMARY2COPYDATA()
Set des = Sheet18.Range("a1")
With Worksheets("SUMMARY")
.Rows(Range("A44").Row).Copy
des.Range("A3").Insert Shift:=xlUp
End With
Application.CutCopyMode = False
End Sub
Please try this:
Sub COPY_SUMMARY2COPYDATA()
Dim LastRow As Long
LastRow = Sheet18.Cells(Rows.Count,1).End(XlUp).Row + 1
Sheets("SUMMARY").Rows("44").Copy
Sheet18.Rows(LastRow).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
Hope this help
To find the first blank cell in column A look from the bottom up and offset down one row.
Use a direct value transfer with .Value2 to pass over 'the data will convert to absolute number'. This will discard regional currency and date conventions as well as formulas in favor of the raw underlying value.
with Worksheets("SUMMARY")
with intersect(.usedrange, .rows(44).cells)
Sheet18.cells(.rows.count, "A").end(xlup).offset(1, 0).resize(.rows.count, .columns.count) = .value2
end with
end with
Related
Please help me fix a macro to paste completed items (Column A) to the next sheet (Completed Tab) then delete it from 1st sheet (Email Tracker) once transferred to Completed Tab. It's behaving like this:
-overwrites the contents in Completed tab, instead of adding additional entries to it
Below is my code.
Sub Clear()
'
' Clear Macro
'
' Keyboard Shortcut: Ctrl+Shift+G
'
Sheets("Email Tracker").Select
Range("A1").AutoFilter Field:=1, Criteria1:= _
"Completed"
ActiveSheet.AutoFilter.Range.Copy
Sheets("Completed").Select
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Sheets("Email Tracker").Select
Range("A1").Select
Application.CutCopyMode = False
ActiveSheet.ShowAllData
End Sub
When you use the macro recorder you should always try to clean up the code and remove "Select". I see where you tried to add last row, but didn't know how to apply it. The code below first sets up the last row (LR) for your destination sheet, so you can properly paste your "completed" emails to the first empty row after the last row in the Destination sheet. Next, it copies your headers from the source sheet to destination sheet, because I don't know if they are already in the destination sheet. Next it filters your source sheet and copies the visible data to your destination sheet, pasting the data to the first empty row below the last row. Then it will delete the visible data on your filtered source sheet. Finally it removes the filter in your source sheet.
Dim LR As Long
With Worksheets("Email Tracker")
Rows(1).EntireRow.Copy Sheets("Completed").Range("A1")
LR = Sheets("Completed").Cells(Rows.Count, 1).End(xlUp).Row
.AutoFilterMode = False
With Range("A1").CurrentRegion
.AutoFilter Field:=1, Criteria1:="Completed"
On Error Resume Next
.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Completed").Cells(LR + 1, 1)
.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
.AutoFilterMode = False
End With
I'm trying to copy data into new workbook and validate the data by removing duplicates keeping one cell value as the source.
All I wanted is the count of XD in the worksheet provided there are no duplicate Record locator.
Also I wanted the count to be in a msgbox. Can someone help ?
Sub openworkbook()
Workbooks.Open ("C:\Users\kjayachandiran\Desktop\ACUITY CF 1204-1210.xls")
Worksheets(2).Activate
Cells.Select
Selection.Copy
Workbooks.Open ("C:\Users\kjayachandiran\Desktop\New-Manjunath.xlsx")
Worksheets(1).Activate
Range("A1").Select
ActiveSheet.Paste
Workbooks(3).Save
Workbooks(2).Close
ActiveWorkbook.Activate
Worksheets(1).Activate
Cells(1, 1).Select
Range("A366655").Value = Application.WorksheetFunction.CountIf(Columns(9), "=" & "XD")
End Sub
Alright so I am really close to getting this but I am just trying to make it work better. I want to copy row 2 formatting that goes until like Column H. The data only goes until Column H. So my code copies ONLY row 2 until Column H. But when it goes to paste, it highlights the whole sheet besides row 1 and it looks like it copies the formatting across the whole thing. It is not really an issue but I would rather know how to make it paste only in the rows and columns I want for future reference. I only want it going to cells that have data in it basically. Thanks for the help in advance!
Range("A2", Cells(2, Columns.Count).End(xlToLeft)).COPY
Range("A2", Cells(Range("A" & Rows.Count).End(xlDown).Row)).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Try this:
Dim rngCopy As Range, rngPaste As Range
With ActiveSheet
Set rngCopy = .Range(.Range("A2"), .Cells(2, Columns.Count).End(xlToLeft))
Set rngPaste = .Range(.Range("A2"), _
.Cells(Rows.Count, 1).End(xlUp)).Resize( , rngCopy.Columns.Count)
End With
rngCopy.Copy
rngPaste.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
I have googled and tried various different things to get this to work but still can't find a solution.
I am still trying to learn about macros and VB so any help would be appreciated.
Basically, what I am after is a cell value on one worksheet to be the amount of rows on a second worksheet.
Picture showing what I am after
As described in the picture, the value of the source cell (number of payments) varies depending on the term/frequency/value of agreement.
I would then like that number of rows be allocated in the next worksheet, with sequential numbering.
This is what I have managed to fumble about with so far....
Sub ExtendByValue()
'
' ExtendByValue Macro
' Extends the rows by the number of repayments
'
'
Sheets("Agreement Tems").Select
Range("C8").Select
Selection.Copy
Sheets("Payments").Select
Range("M1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows("8:8").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
Any help with this is appreciated.
Rows("8:" & (sheets("agreementterms").range("c8").Value + 8)).select
Selection.insert shift:=xldown
incase you have value issues as specified in comments use the below.
Rows("8:" & (sheets("agreementterms").range("c8").text + 8)).select
Selection.insert shift:=xldown
try this
Option Explicit
Sub ExtendByValue()
'
' ExtendByValue Macro
' Extends the rows by the number of repayments
'
Dim nRows As Long
nRows = CLng(Sheets("Agreement Tems").Range("C8")) 'get the integer part of cell "C8" value in "Agreement Tems" sheet
With Sheets("Payments")
.Range("B8").Resize(nRows - 1).EntireRow.Insert 'insert nRows-1 below cell "B8" of "Payments" sheet, so as to have nRows with this latter included
With .Range("B8").Resize(nRows) 'of these nRows ...
.FormulaR1C1 = "=row()- row(R7)" ' ... fill column "B" with a formula returning integer form 1 to nRows ...
.Value = .Value ' ... and finally get rid of formulas and leave only values
End With
End With
End Sub
Using an Excel 2013 workbook, I have changed my Col F and Col AD from formulas to values only in the MFG Hourly Employees worksheet. Is there a way to tweak my code to recognize the first column that has formulas and save as values only, and then the second column the same (currently F4 and AD 4). My code so far is:
Sub SaveAsValuesOnly()
Sheets("MFG Hourly Employees").Select
Range("F4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("AD4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("F4").Select
End Sub
Dim rngCell As Range
For Each rngCell In Selection
If rngCell.HasFormula Then
rngCell.Value = rngCell.Value
End If
Next
The
rng.Value = rng.Value
Removes formulas and keeps values. It looks like you recorded the Makro so i will point it out.
Edit: longer moreexplicit Code with explanation.
Sub removeFormulas()
Dim rngCell As Range
Dim searchRange As Range
searchRange = Worksheets("Sheet1").Range("A1:D10")
For each rngCell In searchRange
If rngCell.HasFormula Then
rngCell.Value = rngCell.Value
End If
Next
End Sub
Explanation:
First we start a sub which is a subprogramm, which will do the trick for your problem. The Sub is started by Sub removeFormulas() and ended with End Sub. Now we set our Variables with Dim X As Ywhere X is the Name and Y the Datatype, here it is the Range Object.
Now we set our searchRange, in which we want to look for formulas, you can set this to fit your needs. In the For Loop we can Loop through every rngCell in our searchRange When we hit Next We return to For, till we looped through all cells in searchRange. The If statement obviosly chekcsif the Cell contains any Formula with the .HasFormula attribute and when it has a formula we just write the visible .Value in the cell and overwrite the formula.