ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populating a cell with the current value of a variable (https://www.excelbanter.com/excel-programming/329608-populating-cell-current-value-variable.html)

Linking to specific cells in pivot table

Populating a cell with the current value of a variable
 
Hi - I'm having problems populating a cell with the current value of a
variable. Basically, I'm trying to do the following:

- set the variable to the value within a specific cell
- paste over a section of a the sheet which inlcudes the cell which was used
to set the variable value in the steop above with blank/null cells
- populate the original cell used to set the variable value with the
variable value

Below is the code I have written which is not working:

Sub clearcontent()

Dim testvalue

Sheets("Frequency Input").Select
range("J2").Select
Set testvalue = Selection

Sheets("Header").Visible = True
Sheets("Header").Select
range("A:G").Select
Selection.Copy
Sheets("Frequency Input").Select
range("J:P").Select
ActiveSheet.Paste

range("J2").Select
Selection = testvalue

Sheets("Header").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Visible = False

End Sub

Bob Phillips[_7_]

Populating a cell with the current value of a variable
 
Sub clearcontent()
Dim testvalue

testvalue = Sheets("Frequency Input").Range("J2").Value

Worksheets("Header").Range("A:G").Copy Destination:= _
Worksheets("Frequency Input").Range("J:P")

Range("J2").Value = testvalue

Application.CutCopyMode = False

End Sub


--
HTH

Bob Phillips

"Linking to specific cells in pivot table"
crosoft.com wrote in
message ...
Hi - I'm having problems populating a cell with the current value of a
variable. Basically, I'm trying to do the following:

- set the variable to the value within a specific cell
- paste over a section of a the sheet which inlcudes the cell which was

used
to set the variable value in the steop above with blank/null cells
- populate the original cell used to set the variable value with the
variable value

Below is the code I have written which is not working:

Sub clearcontent()

Dim testvalue

Sheets("Frequency Input").Select
range("J2").Select
Set testvalue = Selection

Sheets("Header").Visible = True
Sheets("Header").Select
range("A:G").Select
Selection.Copy
Sheets("Frequency Input").Select
range("J:P").Select
ActiveSheet.Paste

range("J2").Select
Selection = testvalue

Sheets("Header").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Visible = False

End Sub





All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com