Change multiple named cells and ranges in a worksheet at once - excel

I want to change a lot of excell names in a worksheet (200+), names are like comp.... and I want to change it in cons.... . So every time is the change the same. Is there a way to do this all at once?
I know for functions it is simple using control h and then replace comp with cons and then they will all change at once. Do you also know whether this is possible for names (so the names of cells and range of cells). It will save me a lot of (especially boring) work. Thanks a lot already!
Best
Timothy

If you know How to use Excel Macro,
Sub RangeRename()
Dim N As Name
For Each N In ActiveWorkbook.Names
N.Name = WorksheetFunction.Substitute(N.Name, "comp", "cons")
Next N
End Sub
If not
Hit Alt+F11
Paste the code from above
Hit F5->Run

Related

Make variable hyperlink from cell data

Hi I am kind of new to VBA and i can't seem to find what i am looking for.
What i want to make is a macro that links to another page in my workbook that refers to data in a certain cell.
from certain datapoints i have a cell set up that as everything is filled in it gives the name of the page i want to link to (lets say "overview_Oct_2020" by filling in the month and year in other cells), and when running the macro go to that.
I seem to totally blank on how to do it. I made a =HYPERLINK() version pretty easily, but i want to change that to a button, hence the reason for a macro.
so technically i want to make a button with a macro that goes to [TEXT IN CEL A1]!A1
Put this macro in a standard module and assign it to a button on the worksheet
Sub link()
Dim textInCelA1 as String
textInCelA1 = Range("A1").value
Sheets(textInCelA1).Activate
Range("A1").Select
End Sub

How to copy specific parts of a table from a sheet to another

I'm trying to get some details copied in Excel from Sheet 1 columns 1-5 to Sheet 2 columns 1-4, but only for lines that include text or values on sheet one under a specific column (in this case, Column 2). There are other columns in between, so I need to be able to use exact columns rather than A:D for example.
Example of what I'm trying to achieve:
I have tried using a simple IF function with A:A<>"" so it would include any rows that have any data in them, however this does not seem to copy as I need and occasionally based on my attempts i also get circular reference errors. Additionally, I’m not sure how to make sure this gets pasted at the bottom of a table that will expand with each addition.
I realize a probably easier option would be to simply copy Sheet 1 entirely and use a filter on row 1 to deselect Blanks on A:A, but the sheet has so much more info that it would be a waste, and additionally info is constantly added so I need something scale-able. It also occurred to me now that by doing this i would include info from the "header" and "footer", basically a frozen pane - which I do not need.
Could this be done via a simple function, or would it require a Macro?
Please keep in mind I'm rubbish at programming, just trying to make my life easier and learn as I go. A lot of excel forums help but still I'm no coder. I can understand to a pretty big degree what the code does and can adjust accordingly though :)
As suggested, this cannot be done with formulas. There are different ways to achieve this.. below is one approach:
Sub CopyFilteredRows()
Dim oSourceSheet As Worksheet: Set oSourceSheet = ThisWorkbook.Worksheets("Sheet3") ' Set your source sheet here
Dim oRng As Range: Set oRng = oSourceSheet.Range("A2:E" & oSourceSheet.Range("C" & oSourceSheet.Rows.Count).End(xlUp).Row)
' Set filter on column B
oRng.AutoFilter
oRng.AutoFilter 2, "<>"
' Copy to specified sheet
oRng.SpecialCells(xlCellTypeVisible).EntireRow.Copy ThisWorkbook.Worksheets("Sheet4").Range("A2") ' Change your destination sheet here
' Clear objects
Set oRng = Nothing
Set oSourceSheet = Nothing
End Sub
Paste the above UDF in a Module and then run it whenever you want to perform the copy. I suspect you would have to modify it a bit so that you can cater for your particular scenario but it should give you a start

What is the best way to cut and paste a column with a defined name to a new worksheet, and why doesn't my code work?

I am attempting to efficiently copy columns of data from one worksheet to a second worksheet in Excel using VBA, starting with a defined name for the column.
I am unsure why my code doesn't work. I cannot emphasis enough, how little I know about coding. I am attempting to teach myself VBA in order to manipulate vast quantities of data in Excel.
Function SortDataC()
'cuts and pastes columns from the unsorted worksheet to the sorted worksheet
Worksheets("UnsortedData").Range("DeltaModScore").Copy Destination:=Worksheets("SortedData").Columns(1)
End Function
DeltaModScore is the column header. If I look in defined named it is present on the sheet UnsortedData with workbook scope. Thus, I assume I have screwed up the syntax somewhere?
I have used the term Sheets("UnsortedData").Range..... as well as Worksheets.... as you see above. I've been basically searching the web for code examples and trying to get them to work with my data. Inevitably, I end up with errors I have much difficulty fixing. I hope this is something simple someone can point out.
You only require the single top left cell of a destination to complete a Copy & Paste.
SUB SortDataC()
'COPIES and pastes columns from the unsorted worksheet to the sorted worksheet
Worksheets("UnsortedData").Range("DeltaModScore").Copy _
Destination:=Worksheets("SortedData").Cells(1, "A")
End SUB
Functions are intended to return a value. If you simply want to complete an operation, a sub procedure is more appropriate.

How to list all excel current regions in one worksheet

In order to navigate through complex spreadsheets that I'm asked to analyse I need a list of all current regions in a worksheet. Excel help does not give me many clues. My solution so far is to loop over areas using the special cells function, but it is rather slow.
Function list_all_current_regions(work_sheet)
Dim current_region_dic As New Dictionary
Set r = work_sheet.Cells(1, 1)
For Each x In Array(xlCellTypeConstants, xlCellTypeFormulas)
Set c = work_sheet.Cells(1, 1).SpecialCells(x, 23)
For Each a In c.Areas
If Not current_region_dic.Exists(a.CurrentRegion.Address) Then
current_region_dic.Add a.CurrentRegion.Address, ""
End If
Next
Next
Set list_all_current_regions = current_region_dic
End Function
Is there a smarter way to list all the current regions in a worksheet?
Over the years I've avoided having multiple ranges on Worksheets for the very reason you are asking about, and I move disconnected content onto its own Worksheet when a client gives me a model designed as a single "ubersheet".
The only way around this I've found is to use Named Ranges. They are accessed using the Names collection attached to the Workbook and Worksheet objects.
One other tip I'll give is to just used the Named Range on the top left cell only then you can use the CurrentRegion property to grab the entire range. This helps when you have expanding regions that you don't want to go in to set and reset the entire range.
https://msdn.microsoft.com/en-us/library/office/ff196678.aspx?f=255&MSPPError=-2147217396

Issue using IF=() function in Excel 2010

I am new to this forum and I am seeking help with creating a function in Excel for data logging purposes. Basically I am trying to use Excel to write a macro simply by pressing "x" in certain cells. For instance, from cells A3-A6 I will have client's names listed there. In addition, I will have dates (of service) listed on the 2nd cell row and on.
9/20 9/21 9/22 9/24
John Doe x
Sara Mitchell x x
Christopher Acha x
Now, I have the macro, I have everything I need in order to set this up. The only problem I am having is to make Excel write the macro for me. I am trying to use the IF=() function, but it limits me to 255 characters, and it tells me to use the concatenate function. All I am trying to do is basically tell Excel that if a certain cell IS true, I would mark it by hitting x; meaning that if a person came on the 24th for service, I would hit x and from there excel would automatically write what I tell it to (in a different sheet or cell). I am stuck here, any help would be greatly appreciated.
You said you have a macro that works, so I'm assuming you want to know how to trigger it automatically when you enter data into a cell.
In your worksheet code use a change event and call your macro from here and pass the range you sent.
Private Sub Worksheet_Change(ByVal Target As Range)
myMacro(Target)
End Sub
You'll probably want to add in additional code to test that the cell changed is within a certain range before calling your macro.

Resources