Friday 15 July 2011

Trying to create excel vba macro that opens new sheet, renames it according to value of relative cell in original sheet -


I have a master list of contacts, I am trying to create a macro that uses a relative reference point :

Open a specific sheet template Give it a name = value of ActiveCell or the first cell active in the macro and copy and paste information Master list to open new sheet

Let me know this How to open and copy and paste the sheet, but the sheet I always get an error when I rename it.

  ActiveCell.Range ("A1, A2: B26"). Select ActiveCell.Offset (1, 0). Range ("A1") Activate active window. ScrollRow = 5 ActiveWindow.ScrollRow = 4 ActiveWindow.ScrollRow = 3 ActiveWindow.ScrollRow = 2 ActiveWindow.ScrollRow = 1 ActiveCell.Offset (-1, 0). Range ("A1") Select Sheet ("Patient List"). Choose Sheet Add type: = _ "C: \ users \ walery \ apeda \ roaming \ microsoft \ template \ patient-history-template 1.xltx" sheets ("patient list"). Select the selection. Copy Sheet ("Patient List"). Choose Sheets ("Patient List"). Select the name = "Patient list" sheet ("Patient 1")   

Below, the place where I want to name the name of the new sheet = "Jones" instead of the first cell active in the macro In this way I can run the macro and get separate letters for each name in the column.

  sheet ("patient 1"). Name = "Jones" Sheets ("Jones"). ActiveSheet Select Paste Paste ("Patient List"). Select ActiveCell.Offset (0, 1). Range ("A1") Select the application. Cotkeypix = wrong selection Copy Sheets ("Jones"). Choose ActiveCell.Offset (0, 1). Range ("A1") Select ActiveSheet.Paste Sheets ("Patient List"). Select ActiveCell.Offset (0, 1). Range ("A1") Select Application.CutCopyMode = False Selection.Copy Sheets ("ActiveCell.Offset (2, -1) .Range (" A1 "). Select ActiveSheet.Paste Sheets (" Patient List ").    

.

You should probably do this in a loop, above the range of cells named patient.

  Sub-TestAdpetithesat () Dimension Range in the form of Range Range as Long Row Eater Dim Patient as Sheet Active in the form of String Moderate Sheet ("Patient List") Set RNG = Set RNG = Sheet ("Patient List") Category ("A2: B26") - This is the number of the name of a patient in Colonel A, which is RNG for R = 1. The name of the patient = RNG (R. 1). The value 'creates a new worksheet Patient Set Sheet = Sheets. (Add: = Sheets ("Patient List"), _ Type: = "C: \ User \ Valery \ Epadata \ Roaming \ Microsoft \ Template \ Patient-History-Template 1.xltx ") Try again: 'Rename attempt' Sheet, trapping errors (if any) and allow retry go to error ErrName: patientSheet.Name = patientName Next Exit sub ErrName: Err.Clear MsgBox patientName & amp; "Do not have a valid worksheet name", vbCritical patientName = InputBox ("Please" & amp; amp;; & amp;; vbCRLF & & quot; Make sure the name of the sheet does not already exist, rename the worksheet. "; _" Is less than 32 characters, and does not include "& amp; vbCRLF and amp; _" special characters such as%, *, etc., "Rename Sheet"; & patientName, patientName) again Start Resume Sub    

No comments:

Post a Comment