Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Verificar el nombre de una hoja de calculo

publicado

Buenos días:

Tengo el siguinte código:

Sub NombreHoja()
   ActiveSheet.Name = Range("B1").Value
   
End Sub

Bueno pone el nombre a la hoja de calculo según el valor de la celda, mi pregunta es de que si hay otra hoja con el mismo nombre me de un aviso para cambiar de nombre o en su caso asignarle por defecto un carater numérico para diferenciarse de la otra hoja que tenga el mismo nombre.

Saludos cordiales

Jesús  

Featured Replies

publicado
Sub NombreHoja()

	Dim Nombre as String
	Dim existe as Boolean
	Dim Hoja as Worksheet

	Nombre = Range("B1").Value
	existe = False
	For each Hoja in ThisWorkbook.Worksheets
		If Hoja.Name = Nombre then
			existe = True
			Exit Sub
		End If
	Next

	if existe = true Then
		MsgBox "Por favor, introduzca otro nombre e intente de nuevo"
		exit Sub
	else
		ActiveSheet.Name = Nombre
	end if
   

End Sub

 

publicado

¡Hola a todos!

Otra opción:

Sub VerificaHoja()
   If Evaluate("ISREF('" & [B1] & "'!A1)") Then
      MsgBox "El nombre de la hoja ya existe. Intente nuevamente"
   Else
      ActiveSheet.Name = [B1]
   End If
End Sub

Nota: En tu macro @YoelMonsalve, debes cambiar la línea Exit Sub por Exit For.

¡Bendiciones!

publicado

Cierto, la escribí "a capella", sin probarla

 

Sub NombreHoja()

	Dim Nombre as String
	Dim existe as Boolean
	Dim Hoja as Worksheet

	Nombre = Range("B1").Value
	existe = False
	For each Hoja in ThisWorkbook.Worksheets
		If Hoja.Name = Nombre then
			existe = True
			Exit for
		End If
	Next

	if existe = true Then
		MsgBox "Por favor, introduzca otro nombre e intente de nuevo"
		exit Sub
	else
		ActiveSheet.Name = Nombre
	end if
   

End Sub

 

publicado

.

Aprovechando On Error:

Sub NombreHoja(): On Error Resume Next
   MsgBox "La hoja " & Sheets(Range("B1").Value).Name & " ya existe"
   ActiveSheet.Name = Range("B1").Value
End Sub

 

  • Silvia bloqueó este tema

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.