Match/resize new range based on another sheets selection - excel

Is it possible to match the range size of sheet 2 with the selected range in sheet 1?

First select Sheet1 and then select some block of cells. After running this macro:
Sub MatchRange()
Dim ady As String
ady = Selection.Address
Sheets("Sheet2").Select
Range(ady).Select
End Sub
you will be on Sheet2 with the same block selected.

Related

How can I extract data from database sheet and paste matched range in different sheets

I have multiple sheets in a workbook. I wan't to copy cells containing SPT values for each Boreholes from the "combine" sheet based on sheetname matching within range listed within "A5:A116" or may be more after final data entry to the sheet matching with the borehole ID /cell value within range "A5:A116" and paste it below the SPT column. This has to continue through a loop process for all the sheets. Also a relative referencing from the matched cell to the range to be copied will be required. In the code the range D5:D16 will have to be a floating ranged based on relative referencing from cell value. Also the paste range will start from 1 cell below the SPT value in the matched.name sheet The code I am working on is as follows the relative referencing for range does not seem to work:
Sub example()
Dim wkSht As Worksheet
For Each wkSht In Sheets
For Each Cell In Sheets("Combine").Range("A5:A116")
If Cell.Value = wkSht.Name Then
On Error Resume Next
Sheets("Combine").Range("D5:D16").Copy Destination:=wkSht.Range("D29:D52")
End If
Next Cell
Next wkSht
End Sub
Data Extraction in different sheets
You sequence for the looping is incorrect, and you did not declare the variable for cell, please try the following code modification and it shall work properly:
Sub example()
Dim wkSht As Worksheet
Dim cell As Range
For Each cell In Sheets("Combine").Range("A5:A116").Cells
For Each wkSht In ThisWorkbook.Worksheets
If cell.Value = wkSht.Name Then
Sheets("Combine").Range(cell.Offset(0, 11), cell.Offset(30, 11)).Copy wkSht.Range("D29")
End If
Next wkSht
Next cell
End Sub

How to paste/equalize specific range value in one sheets into another?

I have named "FormEntry" in Range("E7,F11,H12,I8,E16") in Sheet1.
and picture above is Sheet2.
Is that possible to copy Range "FormEntry" from Sheet1 and paste/equalize into the same Range in Sheets2 without other cells range in Sheet2 being replaced?
I've tried this syntax but the values on Sheets2 are A's
Sub test()
Sheets("Sheet2").Range("E7,F11,H12,I8,E16").Value = Sheets("Sheet1").Range("E7,F11,H12,I8,E16").Value
End Sub
You can use:
For Each cell In Range("FormEntry")
Sheets("Sheet2").Cells(cell.Row, cell.Column).Value = cell.Value
Next

How to loop through cells in a sheet to search another sheet?

I need to search "Check" Sheet for values from "Text" sheet.
How can I create a loop for "Text" sheet from cell value A2 to A4 one by one.
I have created below code
Option Explicit
Dim i As Integer
Dim WS, W As Range
Sub Search_fn()
Set WS = Range("B2")
WS = Application.WorksheetFunction.Search(Sheet2.Range("A2"), Range("A2"), 1)
End Sub
This shows 1004 error and I am also not able to crate the loop for all values.
Sheet "Check"
Sheet "text"

How to automatically include formulas in specific column when an excel workbook is opened?

I have an excel workbook which I am creating with the help of Alteryx. Alteryx populates the cells with values instead of formulas. Now when I open the workbook, I want just one of the columns in Sheet 1 to be populated with formulas (not just pasted values from alteryx). How do I do that using MACROS?
Try this, with the event "Workbook_Open".
the below code will insert when you open the workbook, the formula =SUM(D2,E2) in column A from row 1 to 20
Private Sub Workbook_Open()
Dim CheckRange As Range
Dim x As Range
Set CheckRange = Range("A1:A20")
For Each x In CheckRange
x.Formula = "=SUM(D2,E2)"
Next
End Sub

Excel: Open in the first empty cell

Is it possible to let Excel automatically select the first empty cell in column A, whenever I open the document?
I have got the following to find the the first empty line:
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Value + 1.Count, 1).End(xlUp).Value + 1
In order to get Excel to select the first empty cell in column A when you open your workbook, you need to place the following code in the ThisWorkbook module.
Private Sub Workbook_Open()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Select
End Sub
This will select the first empty cell in the ActiveSheet. If you got multiple sheets in your workbook and you want to select the first empty row in a specific sheet, say Sheet1, you should change the second line of code to:
Set ws = ActiveWorkbook.Sheets("Sheet1")
You can do that.
You need write VBA(macro) program to realize.
Code you need is as follow
Private Sub Workbook_Open()
ActiveWindow.Range("A65536").End(xlUp).Offset(1,0).Select
End Sub
Meaning of code is:
"Private Sub Workbook_Open()" is predefined name subroutine which will be executed when the workbook be opened.
"ActiveWindow.Range("A65536").End(xlUp)" will find last cell with data in A column ("last cell")
"ActiveWindow.Range("A65536").End(xlUp).Offset(1,0)" will move to cell next to "last cell", that will be first blank cell.
ActiveWindow.Range("A65536").End(xlUp).Offset(1,0).Select will select tha first blank cell.
I assumed that you use Excel 2003 or older, OR number of rows with data in your worksheet is less than 65536.
If you use Excel 2007 or newer and you have rows with data in your worksheet more than 65536, please modify 65536 to the value large enough to cover rows in your worksheet.

Resources