Page 34 of 61 FirstFirst ... 24323334353644 ... LastLast
Results 331 to 340 of 604

Thread: Appendix-Thread-Evaluate-Range-(-Codes-for-other-Threads-HTML-Tables-etc-)

  1. #331
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macro for this post
    https://excelfox.com/forum/showthrea...-condition-met

    Code:
    Sub VBAAppendDataToExcelFileRowBasedOnTwoExcelFileConditions2()  '           https://excelfox.com/forum/showthread.php/2517-Copy-and-paste-the-data-if-condition-met   Previous macro where second file is  .csv  text file                https://excelfox.com/forum/showthread.php/2505-copy-paste-the-data-if-condition-matches?p=13616&viewfull=1#post13616
    Rem 1 sample1.xls
    Dim Wb1 As Workbook, Ws1 As Worksheet
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Sample1.xls")
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & "Sample1.xls")
     Set Wb1 = Workbooks("Sample1.xls")
     Set Ws1 = Wb1.Worksheets.Item(1)
    Dim arrWs1() As Variant: Let arrWs1() = Ws1.Range("A1").CurrentRegion.Value2
    Dim Lr1 As Long: Let Lr1 = UBound(arrWs1(), 1)
    Rem 2 sample2.xlsx
    Dim Wb2 As Workbook, Ws2 As Worksheet
     Set Wb2 = Workbooks("Sample2.xlsx")
     Set Ws2 = Wb2.Worksheets.Item(1)
    Dim RwCnt2 As Long: Let RwCnt2 = Ws2.Range("A" & Ws2.Rows.Count & "").End(xlUp).Row
    Dim NxtRw As Long: Let NxtRw = RwCnt2 + 1 ' next free row in sample2.xlsx
    ' 2d) second column in sample2.xlsx up maximum size of  sample1.xls   - that will be the biggest size needed
    Dim Clm2() As Variant: Let Clm2() = Ws2.Range("B1:B" & Lr1 & "").Value  '  Clm2Sample2xlsx.JPG
    
    Rem 3 Do it
    Dim Cnt As Long
        For Cnt = 2 To Lr1 ' considering each data row in  Sample1.xls
        ' ( If column K of sample1.xls is greater than Column D of sample1.xls & Column H of sample1.xls is Greater than column K of sample1.xls ) or ( If column K of sample1.xls is lower than Column D of sample1.xls & Column H of sample1.xls is lower than column K of sample1.xls ) Then
        '                          Condition 1)                                    or         Condition 2)
            If (arrWs1(Cnt, 11) > arrWs1(Cnt, 4) And arrWs1(Cnt, 8) > arrWs1(Cnt, 11)) Or (arrWs1(Cnt, 11) < arrWs1(Cnt, 4) And arrWs1(Cnt, 8) < arrWs1(Cnt, 11)) Then
            Dim MtchRes As Variant ' for match column I of of Sample1.xls with second data column of   Sample2.xls Clm2()
             Let MtchRes = Application.Match(arrWs1(Cnt, 9), Clm2(), 0) ' match column I of of 1.xls with second column data of sample2.xlsx
            ' Match Column I of sample1.xls with second column (column B) of sample2.xlsx
                If Not IsError(MtchRes) Then  ' if it is there then do nothing
                '  match obtsained do nothing
                Else '   it is not present   paste the column I data of sample1.xls to second column values (column B) of sample2.xlsx
                 Let Clm2(NxtRw, 1) = arrWs1(Cnt, 9)
                    If NxtRw <> Lr1 Then Let NxtRw = NxtRw + 1 ' If we are not already at the maximum possible row in column B, Ws2 , then we need to adjust  NxtRw  for next possible missing match
                End If
    
            Else
            ' Neither of the 2 conditions are met so do nothing
            End If
        
        Next Cnt
    
    Rem Paste out adjusted/ added to  Ws2 column B
     Ws2.Range("B1:B" & Lr1 & "").Value = Clm2()
    End Sub





    sample1.xls : https://app.box.com/s/xh58fgjl74w06hvsd53jriqkohdm6a3q
    sample2.xlsx : https://app.box.com/s/np7kbvjydnyiu95pzyrgn76qi1uqg0ma
    vba.xlsm : https://app.box.com/s/lf6otsrl42m6vxxvycjo04zidya6pd2m

  2. #332
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macro to answer this Thread
    https://excelfox.com/forum/showthrea...ete-entire-row





    Code:
    Sub STEP9t() '  https://excelfox.com/forum/showthread.php/2520-Conditionally-compare-the-data-amp-delete-entire-row
    Rem 1 Worksheets info
    '1_1 sample1.xls
    Dim Wb1 As Workbook, Ws1 As Worksheet
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Sample1.xls")
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & "Sample1.xls")
     Set Wb1 = Workbooks("1.xls")
     Set Ws1 = Wb1.Worksheets.Item(1)
    Dim arrWs1() As Variant: Let arrWs1() = Ws1.Range("A1").CurrentRegion.Value2
    Dim Lr1 As Long: Let Lr1 = UBound(arrWs1(), 1)
    Dim arrS1() As Variant 'Let arrS1() = Ws1.Range("A1").CurrentRegion.Value
    Let arrS1() = Ws1.Range("A1:J" & Lr1 & "").Value ' Input data range
    '1_2 Alert.xls
    Dim Wb2 As Workbook, Ws2 As Worksheet
     Set Wb2 = Workbooks("Alert.xls")
     Set Ws2 = Wb2.Worksheets.Item(1)
    Dim RwCnt2 As Long: Let RwCnt2 = Ws2.Range("A" & Ws2.Rows.Count & "").End(xlUp).Row
    '1_2d) second column in Alert.xls
    Dim Clm2() As Variant: Let Clm2() = Ws2.Range("B1:B" & RwCnt2 & "").Value
    
    Rem 3
    Dim Cnt As Long, MtchRes As Variant
        For Cnt = UBound(arrS1(), 1) To 2 Step -1 '  "row" count, Cnt
         Select Case arrS1(Cnt, 10) ' column I
          Case "BUY"   'If column J of 1.xls has buy then
            If arrS1(Cnt, 8) < arrS1(Cnt, 4) Then  ' column H of 1.xls is not greater than column D of 1.xls
             Let MtchRes = Application.Match(arrWs1(Cnt, 9), Clm2(), 0) ' match column I data of 1.xls with column B of alert.xls
                If IsError(MtchRes) Then
                ' no match result so do nothing
                Else
                 Ws2.Range("A" & MtchRes & ":K" & MtchRes & "").Delete shift:=xlUp   ' delete that entire row of alert.xls
                End If:
            Else
            End If
          Case ""      ' If column J of 1.xls has a blank cell then
           Let MtchRes = Application.Match(arrWs1(Cnt, 9), Clm2(), 0) ' match column I data of 1.xls with column B of alert.xls
            If IsError(MtchRes) Then
            ' no match result so do nothing
            Else
             Ws2.Range("A" & MtchRes & ":K" & MtchRes & "").Delete shift:=xlUp   ' delete that entire row of alert.xls
            End If
          Case "SHORT"  'If column J is SHORT then
            If arrS1(Cnt, 8) > arrS1(Cnt, 4) Then ' column H of 1.xls is Greater than than column D
             Let MtchRes = Application.Match(arrWs1(Cnt, 9), Clm2(), 0) ' match column I data of 1.xls with column B of alert.xls
                If IsError(MtchRes) Then
                ' no match result so do nothing
                Else
                 Ws2.Range("A" & MtchRes & ":K" & MtchRes & "").Delete shift:=xlUp   ' delete that entire row of alert.xls
                End If
            Else
            End If
         End Select
        Next Cnt
    
    End Sub




    macro.xlsm : https://app.box.com/s/z358r7tbc9hzthi539dlj49jsf4gyg8p
    1.xls : https://app.box.com/s/38aoip5xi7018y9syt0xe4g04u95l6xk
    Alert.xls : https://app.box.com/s/ectstkrcfnuozys9tmdd0qi3tdvyxb3w

  3. #333
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macro for this post:
    https://excelfox.com/forum/showthrea...ata-if-matches




    Code:
    Sub AddColumnJValueInWs1basedOnMatchAndCritzeriaInWs2() ' https://excelfox.com/forum/showthread.php/2556-copy-and-paste-of-data-if-matches
    Rem 1 Worksheets info
    '1_1 sample1.xls
    Dim Wb1 As Workbook, Ws1 As Worksheet
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Sample1.xls")
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & "Sample1.xls")
     Set Wb1 = Workbooks("1.xls")
     Set Ws1 = Wb1.Worksheets.Item(1)
    Dim arrWs1() As Variant: Let arrWs1() = Ws1.Range("A1").CurrentRegion.Value2
    Dim Lr1 As Long: Let Lr1 = UBound(arrWs1(), 1)
    '1_1b) data range
    Dim arrS1() As Variant 'Let arrS1() = Ws1.Range("A1").CurrentRegion.Value
    Let arrS1() = Ws1.Range("A1:J" & Lr1 & "").Value ' Input data range
    '1_2 AlertCodes.xlsx
    Dim WbA As Workbook, WsA4 As Worksheet
     Set WbA = Workbooks("AlertCodes.xlsx")
     Set WsA4 = WbA.Worksheets.Item(4)
    Dim RwCnt4 As Long: Let RwCnt4 = WsA4.Range("A" & WsA4.Rows.Count & "").End(xlUp).Row
    '1_2b) dataa range
    Dim arrWsA4() As Variant: Let arrWsA4() = WsA4.Range("A1:K" & RwCnt4 & "").Value2
    '1_2d) second column in Alertcodes.xlsx
    Dim ClmB() As Variant: Let ClmB() = WsA4.Range("B1:B" & RwCnt4 & "").Value
    
    Rem 3
    Dim Cnt As Long
        For Cnt = 2 To Lr1 ' going down "rows" in 1.xls
        Dim MtchRes As Variant
         Let MtchRes = Application.Match(arrWs1(Cnt, 9), ClmB(), 0) '  match column I of 1.xls  with sheet4 of column B of Alertcodes.xlsx
            If IsError(MtchRes) Then
            ' do nothing - no match
            Else ' look at symbol in column D, 4th worksheet of AlertCodes.xlsx for that matched row in column D, 4th worksheet of AlertCodes.xlsx
                If arrWsA4(MtchRes, 4) = ">" Then ' If symbol is > then
                 Let arrS1(Cnt, 10) = "SHORT" ' put SHORT in column J of 1.xls for the matched row
                ElseIf arrWsA4(MtchRes, 4) = "<" Then '  If symbol < then
                 Let arrS1(Cnt, 10) = "BUY" ' put BUY in column J of 1.xls for the matched row
                Else
                End If
                
            End If
        Next Cnt
    
    Rem 4 Paste back out arrS1()
     Let Ws1.Range("A1:J" & Lr1 & "").Value2 = arrS1()
    End Sub
    



    AlertCodes.xlsx : https://app.box.com/s/jwpjjut9wt3ej7dbns3269ftlpdr7xsm
    1.xls : https://app.box.com/s/38aoip5xi7018y9syt0xe4g04u95l6xk
    Vba.xlsm : https://app.box.com/s/lf6otsrl42m6vxxvycjo04zidya6pd2m

  4. #334
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    In support of these posts
    https://excelfox.com/forum/showthrea...ll=1#post13617
    https://excelfox.com/forum/showthrea...ll=1#post13470

    sample2BEFORE.csv
    NSE,101010,6,<,12783,A,,,,,GTT
    NSE,22,6,<,12783,A,,,,,GTT
    NSE,17388,6,<,12783,A,,,,,GTT

    Code:
    "NSE" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf & "NSE" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf & "NSE" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf
    Code:
    "NSE" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf & "NSE" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf & "NSE" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf
    sampLE2AFTER.csv
    NSE,101010,6,<,12783,A,,,,,GTT
    NSE,22,6,<,12783,A,,,,,GTT
    NSE,17388,6,<,12783,A,,,,,GTT
    ,100,,,,,,,,,
    ,25,,,,,,,,,

    Code:
    "NSE" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf & "NSE" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf & "NSE" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & vbCr & vbLf & "," & "100" & "," & "," & "," & "," & "," & "," & "," & "," & "," & vbCr & vbLf & "," & "25" & "," & "," & "," & "," & "," & "," & "," & "," & "," & vbCr & vbLf
    Code:
    "NSE" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf & "NSE" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf & "NSE" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & 
    vbCr & vbLf & "," & "100" & "," & "," & "," & "," & "," & "," & "," & "," & "," & 
    vbCr & vbLf & "," & "25" & "," & "," & "," & "," & "," & "," & "," & "," & "," & 
    vbCr & vbLf



    https://excelfox.com/forum/showthrea...ll=1#post13617
    sampLE2AFTER.csv : https://drive.google.com/file/d/1Tyf...gWwzZ3s43YxzwA
    sample2BEFORE : https://drive.google.com/file/d/1X2M...vIqNATRC34o5hD


    app.box.com
    Share ‘sample2BEFORE.csv’ : https://app.box.com/s/d8lu7iatfv6h8spp9eru8asm3h4v4e4p
    Share ‘Sample2After.csv’ : https://app.box.com/s/0j4118cwzzofe76ytb5rqkvz3qj0vseu











    Previous files:
    sample2.csv : https://app.box.com/s/0ej2h41g9fvm94cflf2j60a8o6p3334t
    Sample1.xls : https://app.box.com/s/xh58fgjl74w06hvsd53jriqkohdm6a3q
    macro.xlsm : https://app.box.com/s/z358r7tbc9hzthi539dlj49jsf4gyg8p
    Sample2After.csv : https://app.box.com/s/0j4118cwzzofe76ytb5rqkvz3qj0vseu
    vba.xlsm : https://app.box.com/s/juekenyll42z84j6ms7qonzsngnugoyo

  5. #335
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macro for this post:
    https://excelfox.com/forum/showthrea...ll=1#post13617


    Code:
    Sub VBAAppendDataToTextFileLineBasedOnTheTextFileAndExcelFileConditions2()  '   https://excelfox.com/forum/showthread.php/2505-copy-paste-the-data-if-condition-matches?p=13616&viewfull=1#post13616
    Rem 1 Workbook, Worksheet info ( Excel File )
    Dim Wb As Workbook, Ws As Worksheet
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & "\" & "Sample1.xls")
    ' Set Wb = Workbooks.Open(ThisWorkbook.Path & Application.PathSeparator & "Sample1.xls")
     Set Wb = Workbooks("1.xls") '  Workbooks("Sample1.xls") ' CHANGE TO SUIT
     Set Ws = Wb.Worksheets.Item(1)
    Dim arrWs() As Variant: Let arrWs() = Ws.Range("A1").CurrentRegion.Value2
    Dim LR As Long: Let LR = UBound(arrWs(), 1)
    Rem 2 text File Info, Import into Excel Array
    Dim PathAndFileName As String, TotalFile As String
    ' Let PathAndFileName = ThisWorkbook.Path & "\" & "Alert 24 Mai..csv"    '
     Let PathAndFileName = ThisWorkbook.Path & Application.PathSeparator & "sample2BEFORE.csv"  '  "sample2_9June.csv"    ' "sample2 8June.csv"  '   "Sample2.csv" ' "sample2 ef 5 June.csv"    ' CHANGE TO SUIT    From Avinash  : https://excelfox.com/forum/showthread.php/2505-copy-paste-the-data-if-condition-matches?p=13470&viewfull=1#post13470   sample2 ef 5 June.csv : https://app.box.com/s/0j4118cwzzofe76ytb5rqkvz3qj0vseu
    ' 2a)(i) Determine rows (records) wanted, based on ... First column(field) not being empty
    Dim RwCnt As Long, TextFileLineIn As String
    Dim FileNum As Long: Let FileNum = FreeFile(1)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
     Open PathAndFileName For Input As #FileNum 'Open Route to data
     Line Input #FileNum, TextFileLineIn  '  First line
        Do While Not EOF(FileNum) = True And Left(TextFileLineIn, 4) = "NSE," '  Left(TextFileLineIn, 4) = "NSE," ' For text file lines like   NSE,101010,6,<,12783,A,,,,,GTT that may have extra unwanted lines like in one Avinash uses stupidly for explanations
         Let RwCnt = RwCnt + 1 ' for first and subsequent lines given by below. ... but
         Line Input #FileNum, TextFileLineIn '  next line in text file
        Loop
        If EOF(FileNum) = True Then Let RwCnt = RwCnt + 1    '                  ... but if the last line I want is EOF, I will not catch it in the loop so must add a 1 here
     Close #FileNum
    ' 2a)(ii) get the text file as a long single string
     Let FileNum = FreeFile(1)
     Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundemental type data input...
     Let TotalFile = Space(LOF(FileNum)) '....and wot recives it has to be a string of exactly the right length
     Get #FileNum, , TotalFile
     Close #FileNum
    ' 2b) Split into wholes line _ splitting the text file into rows by splitting by vbCr & vbLf ( Note vbCr & vbLf = vbNewLine )
    Dim arrRws() As String: Let arrRws() = Split(TotalFile, vbCr & vbLf, -1, vbBinaryCompare)
    'Dim RwCnt As Long: Let RwCnt = UBound(arrRws()) + 1    '  +1 is nedeed as the  Split Function  returns indicies 0 1 2 3 4 5   etc...
    '  Alert 24 MaiDotDotcsvBefore.JPG  :  https://imgur.com/jSZV7Bt , https://imgur.com/ckS9Rzq
    ' 2c) ' we can now make an array for all the rows, and we know our columns are A-K = 11 columns
    Dim arrIn() As String: ReDim arrIn(1 To RwCnt, 1 To 11)
    Dim Cnt As Long
        For Cnt = 1 To RwCnt '               _.. considering each row of data but only those up to Rwcnt
        Dim arrClms() As String
         Let arrClms() = Split(arrRws(Cnt - 1), ",", -1, vbBinaryCompare)  '  ___.. splitting each row into columns by splitting by the comma
        Dim Clm As Long   '
             For Clm = 1 To 11
            'For Clm = 1 To UBound(arrClms()) + 1
             Let arrIn(Cnt, Clm) = arrClms(Clm - 1)
            Dim TruncRw As String                              '_-
             Let TruncRw = TruncRw & arrIn(Cnt, Clm) & ","     '_- The idea of this is a bodge to  get rid of a lot of extra ,,,,,,, if we have empty cells being used, as in Avinash original -  sample2.csv : https://app.box.com/s/0ej2h41g9fvm94cflf2j60a8o6p3334t   -   https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=13475&viewfull=1#post13475
            Next Clm
         Let arrRws(Cnt - 1) = Left(TruncRw, Len(TruncRw) - 1) '_- take off the last ,
         Let TruncRw = ""                                      '_- so this can be used again for next line(row)
        Next Cnt
    ' 2d) Re make text string of just rows to RwCnt
    ReDim Preserve arrRws(0 To RwCnt - 1)
    Dim TotalFileToRwCnt As String
     Let TotalFileToRwCnt = Join(arrRws(), vbCr & vbLf) & vbCr & vbLf ' This is effectively our long string text file and an extra final carriage return and line feed
    ' 2d) second column in text file, up to RwCnt
    Dim Clm2() As Variant: Let Clm2() = Application.Index(arrIn(), 0, 2) '    https://excelfox.com/forum/showthread.php/1111-VBA-Trick-of-the-Week-Slicing-an-Array-Without-Loop-%e2%80%93-Application-Index    Clm2Sample2csv.JPG :  https://imgur.com/DYYAl3z
    
    Rem 3 Do it
        For Cnt = 2 To LR ' considering each data row in  Sample1.xls
        ' ( If column K of sample1.xls is greater than Column D of sample1.xls & Column H of sample1.xls is Greater than column K of sample1.xls ) or ( If column K of sample1.xls is lower than Column D of sample1.xls & Column H of sample1.xls is lower than column K of sample1.xls ) Then
        '                          Condition 1)                                    or         Condition 2)
            If (arrWs(Cnt, 11) > arrWs(Cnt, 4) And arrWs(Cnt, 8) > arrWs(Cnt, 11)) Or (arrWs(Cnt, 11) < arrWs(Cnt, 4) And arrWs(Cnt, 8) < arrWs(Cnt, 11)) Then
            Dim MtchRes As Variant ' for match column I of of Sample1.xls with second data column of text file  Sample2.csv  Clm2()
             Let MtchRes = Application.Match(CStr(arrWs(Cnt, 9)), Clm2(), 0) ' match column I of of 1.xls with second column data of text file of Alert..csv
            ' Match Column I of sample1.xls with second field values (column B) of sample2.csv
                If Not IsError(MtchRes) Then  ' if it is there then do nothing
                '  match obtsained do nothing
                Else '   it is not present   paste the column I data of sample1.xls to append second field values (column B) of sample2.csv
                 Let TotalFileToRwCnt = TotalFileToRwCnt & "," & arrWs(Cnt, 9) & ",,,,,,,,,," & vbCr & vbLf ' make the single text string for the output text file
                End If
    
            Else
            ' Neither of the 2 conditions are met so do nothing
            End If
        
        Next Cnt
    
    Rem 5 remake the text file
    ''5a) make a new text file string
    'Dim strTotalFile As String
    ' Let strTotalFile = Join(arrRwsOut(), vbCr & vbLf)
    '5b) make new file
    Let FileNum = FreeFile(1)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
     Open ThisWorkbook.Path & "\" & "Sample2After.csv" For Output As #FileNum  ' CHANGE TO SUIT  ' Will be made if not there
     Print #FileNum, TotalFileToRwCnt '                      strTotalFile
     Close #FileNum
    ' Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(TotalFileToRwCnt)
    
    Rem 6 Check File in Excel VBA open
    ' Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Sample2.csv"
    ' Workbooks.Open Filename:=ThisWorkbook.Path & Application.PathSeparator & "Sample2After.csv" ' CHANGE TO SUIT
    'Dim Wb As Workbook
    ' Set Wb = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\sample2.csv")
    End Sub




    Share ‘sample2BEFORE.csv’ : https://app.box.com/s/d8lu7iatfv6h8spp9eru8asm3h4v4e4p
    Share ‘Sample2After.csv’ : https://app.box.com/s/0j4118cwzzofe76ytb5rqkvz3qj0vseu
    vba.xlsm : https://app.box.com/s/juekenyll42z84j6ms7qonzsngnugoyo
    Sample1.xls : https://app.box.com/s/xh58fgjl74w06hvsd53jriqkohdm6a3q
    macro.xlsm : https://app.box.com/s/z358r7tbc9hzthi539dlj49jsf4gyg8p
    1.xls : https://app.box.com/s/38aoip5xi7018y9syt0xe4g04u95l6xk


  6. #336
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10

    Add Worksheets from name list and automatically change worksheet Names when name list is changed

    Question 1

    Solution for this question, ( 2020-05-28 22:13:09 Rajesh Kumar )
    https://excel.tips.net/T002145_Dynam...Tab_Names.html





    Question: ( Question 1 )
    ......I have a list of 80 students. I have made 80 sheets, 1 sheet for 1 student. I want to rename these 80 sheets on the basis of the name in the list, so that whenever I update the name list, the corresponding sheet-name changed automatically. I'm a beginner in this field. Please help me.

    Solution.
    Hello Rajesh
    This requirement is fairly easy with VBA

    There are 3 macros which I have written for you, and I am returning 2 workbook examples

    Macro for your original requirement
    Private Sub Worksheet_Change(ByVal Target As Range)
    This macro is in both workbooks:
    It does this: If you change any of your names in column B of the worksheets, then the name of the corresponding worksheet tab Name will change, as per your main original requirement.

    Workbook AddNamesfromListToExistingWorksheets.xlsm
    This is the workbook supplied by you. It has initially 80 student names in column B of the first worksheet. It has 80 additional worksheets , as made by you, with the names of 1 2 3 4 5 …. Etc.
    This workbook has a macro , Sub ChangeNamesToExistingWorksheets() . This macro replaces those names with the names from the Student name list in column B

    Workbook AddWorksheetsNamedFromList.xlsm
    This is your original Workbook, with all but the first worksheet deleted. So this only contains one worksheet containing your list of student Names in column B
    In this workbook, there is a macro, Sub AddWorksheetsfromListOfNames()
    This macro adds worksheets with the student Names




    Note: in your supplied data, you had two identical names at row 26 and at row 75, SACHIN KUMAR , so I changed it to SACHIN KUMAR 2 in row 75
    ( We could handle such cases in coding, automatically, later if you preferred )


    Alan




    Workbooks:
    Share ‘AddNamesfromListToExistingWorksheets.xlsm’ : https://app.box.com/s/2ytj6qrsyaudh3tzgtodls8l05zn1woz
    Share ‘AddWorksheetsNamedFromList.xlsm’ : https://app.box.com/s/yljwyk5ykxtjt2qhzvdpwcrft19phx54
    For macros, see also post https://excelfox.com/forum/showthrea...ll=1#post13444





    Cross posts
    https://excel.tips.net/T002145_Dynamic_Worksheet_Tab_Names.html ( 2020-05-28 22:13:09 Rajesh Kumar ) https://excel.tips.net/T002145_Dynam...Tab_Names.html
    https://www.mrexcel.com/board/threads/vba-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-value.1135674/ https://www.mrexcel.com/board/thread...value.1135674/

  7. #337
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macros for this post ( Question 1 )
    https://excelfox.com/forum/showthrea...ll=1#post13443

    Code:
    Option Explicit
    
    '  https://excel.tips.net/T002145_Dynamic_Worksheet_Tab_Names.html   '    https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=13443&viewfull=1#post13443    https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=13443&viewfull=1#post13444
    
    Sub RemoveAllButThisWorksheet()
    Dim Cnt
        For Cnt = ThisWorkbook.Worksheets.Count To 2 Step -1 ' second worksheet counting tab from the left is worksheets item 2
         Let Application.DisplayAlerts = False
         ThisWorkbook.Worksheets.Item(Cnt).Delete
         Let Application.DisplayAlerts = True
        Next Cnt
    End Sub
    Sub ChangeNamesToExistingWorksheets() '
    Rem 0
    On Error GoTo Bed                      '       If we have problems then we want to make sure that we still  re enable  Events coding before ending the macro
     Let Application.EnableEvents = False  '       This will prevent anything we do in this macro from causing erratic working of any automatic event coding
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Name List")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("B" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant               '      The  .Value2  property in the next line will return a field of values housed in Variant type Elements, so we need to  give the variant type to our array used to capture that  array  of values
     Let arrNmes() = Ws1.Range("B1:B" & Lr1 & "").Value2
    Rem 2 Add and name worksheets from list
    Dim Cnt As Long
        For Cnt = 2 To UBound(arrNmes(), 1) ' From (2,1) To (2,Lr1) in names array list column 2 ( column B )
         Let Worksheets.Item(Cnt).Name = arrNmes(Cnt, 1)
        Next Cnt
    Bed:  ' error handling code section.
     Let Application.EnableEvents = True
    End Sub
    
    Sub AddWorksheetsfromListOfNames()
    Rem 0
    On Error GoTo Bed
     Let Application.EnableEvents = False
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Name List")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("B" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant
     Let arrNmes() = Ws1.Range("B1:B" & Lr1 & "").Value2
    Rem 2 Add and name worksheets from list
    Dim Cnt As Long
        For Cnt = 2 To UBound(arrNmes(), 1) ' From (2,1) To (2,Lr1) in names array list column 2
         Worksheets.Add After:=Worksheets.Item(Worksheets.Count)
         Let ActiveSheet.Name = arrNmes(Cnt, 1)
        Next Cnt
        
    Bed:
     Let Application.EnableEvents = True
    End Sub
    '
    '
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If IsArray(Target.Value) Then Exit Sub ' If we have changed more than 1 cell, our code lines below will error, so best do nothing in such a case
    Dim Ws1 As Worksheet
     Set Ws1 = Me
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("B" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    
    Dim Rng As Range
     Set Rng = Ws1.Range("B2:B" & Lr1 & "")
        If Not Intersect(Rng, Target) Is Nothing Then ' The Excel VBA Application.Intersect method returns the range where all the given ranges cross, or   Nothing  if there are no common cells.  So, in this example,  we would have  Nothing  if our selection ( which VBA supplies in Target ) , did not cross our names list      '  https://docs.microsoft.com/en-us/office/vba/api/excel.application.intersect
        Dim Rw As Long
         Let Rw = Target.Row
         Let ThisWorkbook.Worksheets.Item(Rw).Name = Target.Value ' In the list, each row number corresponds to the item number of our worksheets made from that list
        Else
        ' changed cell was not in Student name list
        End If
    
    End Sub
    





    Cross posts
    https://excel.tips.net/T002145_Dynamic_Worksheet_Tab_Names.html ( 2020-05-28 22:13:09 Rajesh Kumar ) https://excel.tips.net/T002145_Dynam...Tab_Names.html
    https://www.mrexcel.com/board/threads/vba-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-value.1135674/ https://www.mrexcel.com/board/thread...value.1135674/

  8. #338
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macro for these posts ( Question 2 )
    https://excelfox.com/forum/showthrea...ll=1#post13442
    https://excelfox.com/forum/showthrea...ll=1#post13448

    Code:
    '  _1. I want to create 5 tabs (Sheets) on the basis of these 5 names. (Now the workbook will have 6 tabs, including Master Sheet)   https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13445#post13445
    Sub AddWorksheetsfromListOfNames2() '   https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13445#post13445    https://www.mrexcel.com/board/threads/vba-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-value.1135674/
    Rem 0
    On Error GoTo Bed                      '       If we have problems then we want to make sure that we still  re enable  Events coding before ending the macro
     Let Application.EnableEvents = False  '       This will prevent anything we do in this macro from causing erratic working of any automatic event coding
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Master Sheet")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant
     Let arrNmes() = Ws1.Range("A1:A" & Lr1 & "").Value2
    Rem 2 Add and name worksheets from list
    Dim Cnt As Long
        For Cnt = 1 To UBound(arrNmes(), 1) ' From (2,1) To (2,Lr1) in names array list column 1 ( Column A )
         Worksheets.Add After:=Worksheets.Item(Worksheets.Count)
         Let ActiveSheet.Name = arrNmes(Cnt, 1)
        Next Cnt
    
    Bed:
     Let Application.EnableEvents = True
    End Sub   '      (Now the workbook will have 6 tabs, including Master Sheet)
    
    Sub AddHypolinkToWorksheet()  '   https://www.mrexcel.com/board/threads/vba-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-value.1135674/
    Rem 0
    On Error GoTo Bed                      '       If we have problems then we want to make sure that we still  re enable  Events coding before ending the macro
     Let Application.EnableEvents = False  '       This will prevent anything we do in this macro from causing erratic working of any automatic event coding
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Master Sheet")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant
     Let arrNmes() = Ws1.Range("A1:A" & Lr1 & "").Value2
    
    Rem 2 Add hyperlinks
     Ws1.Hyperlinks.Delete
    Dim Cnt
        For Cnt = 1 To Lr1         '  ='F:\Excel0202015Jan2016\OffenFragensForums\AllenWyatt\[DynamicWorksheetNamesLinkHideBasedOnCellValue.xlsm]RAHIM'!$A$1
        Dim Paf As String: Let Paf = "='" & ThisWorkbook.Path & "\[" & ThisWorkbook.Name & "]" & arrNmes(Cnt, 1) & "'!$A$1"
    '     Ws1.Hyperlinks.Add Anchor:=Ws1.Range("A" & Cnt & ""), Address:="", SubAddress:="='" & arrNmes(Cnt, 1) & "'!A1", ScreenTip:=arrNmes(Cnt, 1), TextToDisplay:=arrNmes(Cnt, 1)
         Ws1.Hyperlinks.Add Anchor:=Ws1.Range("A" & Cnt & ""), Address:="", SubAddress:=Paf, ScreenTip:=arrNmes(Cnt, 1), TextToDisplay:=arrNmes(Cnt, 1)
        Next Cnt
    Bed:  ' error handling code section.
     Let Application.EnableEvents = True
    End Sub
    
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If IsArray(Target.Value) Then Exit Sub ' If we have changed more than 1 cell, our code lines below will error, so best do nothing in such a case
    Dim Ws1 As Worksheet
     Set Ws1 = Me
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    
    Dim Rng As Range
     Set Rng = Ws1.Range("A1:A" & Lr1 & "")
        If Not Intersect(Rng, Target) Is Nothing Then ' The Excel VBA Application.Intersect method returns the range where all the given ranges cross, or   Nothing  if there are no common cells.  So, in this example,  we would have  Nothing  if our selection ( which VBA supplies in Target ) , did not cross our names list      '  https://docs.microsoft.com/en-us/office/vba/api/excel.application.intersect
        Dim Rw As Long
         Let Rw = Target.Row
            If Target.Value = "" Then '  5. If I delete the content of A1 (ANUJ), i.e, if cell A1 is blank, the corresponding sheet "ANUJ" should hide automatically.
             ThisWorkbook.Worksheets.Item(Rw + 1).Visible = False
            Exit Sub
            Else
             ThisWorkbook.Worksheets.Item(Rw + 1).Visible = True
             Let ThisWorkbook.Worksheets.Item(Rw + 1).Name = Target.Value ' In the list, each row number corresponds to one less than the item number of our worksheets made from that list
            End If
        Else
        ' changed cell was not in Student name list
        End If
    
    '
    Call AddHypolinkToWorksheet
    End Sub





    Share ‘DynamicWorksheetNamesLinkHideBasedOnCellValu e. : https://app.box.com/s/louq07ga6uth1508e572l7zr9fakont9

  9. #339
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    Macros for this post
    https://excelfox.com/forum/showthrea...ll=1#post13456

    Add Workseets from names list, for example from :

    _____ Workbook: DynamicWorksheetNamesLinkHideBasedOnCellValueC.xls m ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    3
    4
    ANUJ
    5
    RITA
    6
    MUKESH
    7
    RAM
    8
    RAHIN
    9
    Anshu
    10
    Worksheet: Master Sheet

    Code:
    '  _1. I want to create  tabs (Sheets) on the basis of  names.  https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13456&viewfull=1#post13456    https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13445#post13445
    Sub AddWorksheetsfromListOfNamesC() '   https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13456&viewfull=1#post13456  https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13445#post13445    https://www.mrexcel.com/board/threads/vba-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-value.1135674/
    Rem 0
    On Error GoTo Bed                      '       If we have problems then we want to make sure that we still  re enable  Events coding before ending the macro
     Let Application.EnableEvents = False  '       This will prevent anything we do in this macro from causing erratic working of any automatic event coding
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Master Sheet")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count & "").End(xlUp).Row  '  Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant
     Let arrNmes() = Ws1.Range("C4:C" & Lr1 & "").Value2   '  Range("A1:A" & Lr1 & "").Value2
    Rem 2 Add and name worksheets from list
    Dim Cnt As Long
        For Cnt = 1 To UBound(arrNmes(), 1) ' From (2,1) To (2,Lr1) in names array list column 1 ( Column A )
         Worksheets.Add After:=Worksheets.Item(Worksheets.Count)
         Let ActiveSheet.Name = arrNmes(Cnt, 1)
        Next Cnt
     Worksheets.Item(1).Select
    Bed:
     Let Application.EnableEvents = True
    End Sub   '
    



    Add hypelinks to Worksheets

    Code:
    Sub AddHypolinkToWorksheet()
    Rem 0
    On Error GoTo Bed                      '       If we have problems then we want to make sure that we still  re enable  Events coding before ending the macro
     Let Application.EnableEvents = False  '       This will prevent anything we do in this macro from causing erratic working of any automatic event coding
    Rem 1 worksheets 1 info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1) ' or Worksheets("Master Sheet")    '  first worksheet counting tab from the left is worksheets item 1
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count & "").End(xlUp).Row '  Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
    Dim arrNmes() As Variant
     Let arrNmes() = Ws1.Range("C4:C" & Lr1 & "").Value2    '  Range("A1:A" & Lr1 & "").Value2
    
    Rem 2 Add hyperlinks
     Ws1.Hyperlinks.Delete
    Dim Cnt
        For Cnt = 4 To Lr1         '                                                                                         ='F:\Excel0202015Jan2016\OffenFragensForums\AllenWyatt\[DynamicWorksheetNamesLinkHideBasedOnCellValue.xlsm]RAHIM'!$A$1
        Dim Paf As String: Let Paf = "='" & ThisWorkbook.Path & "\[" & ThisWorkbook.Name & "]" & arrNmes(Cnt - 3, 1) & "'!$A$1"   '   "='" & ThisWorkbook.Path & "\[" & ThisWorkbook.Name & "]" & arrNmes(Cnt, 1) & "'!$A$1"
    '     Ws1.Hyperlinks.Add Anchor:=Ws1.Range("A" & Cnt & ""), Address:="", SubAddress:="='" & arrNmes(Cnt, 1) & "'!A1", ScreenTip:=arrNmes(Cnt, 1), TextToDisplay:=arrNmes(Cnt, 1)
         Ws1.Hyperlinks.Add Anchor:=Ws1.Range("C" & Cnt & ""), Address:="", SubAddress:=Paf, ScreenTip:=arrNmes(Cnt - 3, 1), TextToDisplay:=arrNmes(Cnt - 3, 1) '   Ws1.Range("A" & Cnt & ""), Address:="", SubAddress:=Paf, ScreenTip:=arrNmes(Cnt, 1), TextToDisplay:=arrNmes(Cnt, 1)
        Next Cnt
    Bed:  ' error handling code section.
     Let Application.EnableEvents = True
    End Sub
    '



    Event macros

    Code:
    '
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)  '    https://excelfox.com/forum/showthread.php/2501-VBA-for-dynamic-sheets-name-dynamic-link-hide-sheets-based-on-a-cell-Value?p=13456&viewfull=1#post13456
        'If Target.Column = 1 And Not IsArray(Target.Value) Then ' we are in column A ,  And  we selected one cell
        If Target.Column = 3 And Not IsArray(Target.Value) Then ' we are in column C ,  And  we selected one cell
         Set LRng = Target
        Else
    
        End If
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If IsArray(Target.Value) Then Exit Sub ' If we have changed more than 1 cell, our code lines below will error, so best do nothing in such a case
    Dim Ws1 As Worksheet
     Set Ws1 = Me
    Dim Lr1 As Long
     Let Lr1 = Ws1.Range("C" & Ws1.Rows.Count & "").End(xlUp).Row   '   Range("A" & Ws1.Rows.Count & "").End(xlUp).Row '    http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=11466&viewfull=1#post11466      Making Lr dynamic ( using rng.End(XlUp) for a single column. )
        If Not LRng Is Nothing And Target.Value = "" And LRng.Row = Lr1 + 1 Then Let Lr1 = Lr1 + 1
    Dim Rng As Range
     Set Rng = Ws1.Range("C4:C" & Lr1 & "")    '   Ws1.Range("A1:A" & Lr1 & "")
        If Not Intersect(Rng, Target) Is Nothing Then ' The Excel VBA Application.Intersect method returns the range where all the given ranges cross, or   Nothing  if there are no common cells.  So, in this example,  we would have  Nothing  if our selection ( which VBA supplies in Target ) , did not cross our names list      '  https://docs.microsoft.com/en-us/office/vba/api/excel.application.intersect
        Dim Rw As Long
         Let Rw = Target.Row
            If Target.Value = "" Or Target.Value = "-" Then '  5. If I delete the content of A1 (ANUJ), i.e, if cell A1 is blank, the corresponding sheet "ANUJ" should hide automatically.
             Let Application.EnableEvents = False
             Let Target.Value = ""
             Let Application.EnableEvents = True
    '         ThisWorkbook.Worksheets.Item(Rw + 1).Visible = False
             ThisWorkbook.Worksheets.Item(Rw + 1 - 3).Visible = False
            Exit Sub
            Else
    '         ThisWorkbook.Worksheets.Item(Rw + 1).Visible = True
    '         Let ThisWorkbook.Worksheets.Item(Rw + 1).Name = Target.Value ' In the list, each row number corresponds to one less than the item number of our worksheets made from that list
             ThisWorkbook.Worksheets.Item(Rw + 1 - 3).Visible = True
             Let ThisWorkbook.Worksheets.Item(Rw + 1 - 3).Name = Target.Value
            End If
        Else
        ' changed cell was not in Student name list
        End If
    
    '
    Call AddHypolinkToWorksheet
    End Sub



    Top 2 lines of code module
    Code:
    Option Explicit
    Dim LRng As Range




    File:
    DynamicWorksheetNamesLinkHideBasedOnCellValueC.xls m : https://app.box.com/s/alo1fbzx8r41jd81rttghikytqzvm0w9

  10. #340
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,479
    Rep Power
    10
    kkfhhfsfhsah

Similar Threads

  1. Testing Concatenating with styles
    By DocAElstein in forum Test Area
    Replies: 2
    Last Post: 12-20-2020, 02:49 AM
  2. testing
    By Jewano in forum Test Area
    Replies: 7
    Last Post: 12-05-2020, 03:31 AM
  3. Replies: 18
    Last Post: 03-17-2019, 06:10 PM
  4. Concatenating your Balls
    By DocAElstein in forum Excel Help
    Replies: 26
    Last Post: 10-13-2014, 02:07 PM
  5. Replies: 1
    Last Post: 12-04-2012, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •